[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Collapse]CodeRush
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
 [Expand]Visualization Tools
 [Expand]Code Style Assistance
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Collapse]Unit Testing Assistance
   Testing Framework Configuration
   Running and Debugging Tests
   Test Execution Output
   Working with Test Sessions
   Code Coverage Calculation
   JavaScript Test Runner
   Unit Test Builder
 [Expand]Decompiling Tools
 [Expand]Configuration Options
 [Expand]Extensibility
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Unit Test Builder

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

Expanded 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:

  • 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.

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.

  • Press the Enter key to apply your choice.

CodeRush shows the Test Builder message box.

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.

Add a Test to a New Test Fixture

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

  • The Unit Test Builder message box appears.

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

  • Click OK to close the message box.

  • End your debugging session and see the generated test.

Is this topic helpful?​​​​​​​