The requested page is not available for the requested platform. You are viewing the content for Default platform.
All docs
V18.2
19.1 (preview)
18.2
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Unit Test Builder

The Unit Test Builder tool helps you generate test cases as you are stepping through code.

How to Use

Do the following to generate a new test case:

  • Add a reference to a test framework in your test project.
Note

Unit Test Builder supports projects with references to NUnit, XUnit and VSTest frameworks.

  • Start your debugging session.

  • Place the caret on a method for which you want to generate a test.

For example, the Square method below should return 9 instead of 6 if you pass 3 to this method:

Unit Builder

  • Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.

  • Click the "Generate Test In" item from the menu and choose the location for a test method from the list.

Generate In

You can place a test method inside an existing test class, or create a new test fixture.

Add a Test to the Existing Class

The red target picker appears after you selected the existing text class item from the "Generate Test In" submenu.

  • Choose the position of a test method inside a class with the Up Arrow and Down Arrow keys.

Picker

  • Press the Enter key to apply your choice.

CodeRush shows the Test Builder message box.

Picker

This message box informs you that the Unit Test Builder will generate test after you end your debugging session.

  • Add remarks (optional) in the Test Builder message box. These remarks appear in a test method's comment.

  • Click OK to close the message box.

  • End your debugging session to see the generated test.

The screencast below shows these steps in detail.

Unit Bilder

Add a Test to a New Test Fixture

  • Select the "New Fixture in Test" item from the Generate Test In sub menu.

Fixture

  • The Unit Test Builder message box appears.

InvokedBox

  • Add remarks (optional) in the Test Builder message box. These remarks appear in the comment within a test method.

FixtureMessage

  • Click OK to close the message box.

  • End your debugging session and see the generated test.

GeneratedTest