Templates for Unit Tests

This topic describes integrated templates that simplify writing unit tests.

The following test frameworks are supported out of the box.

  • MbUnit
  • MSTest
  • NUnit
  • xUnit

Creating a Test Fixtures and Test Methods

To start writing a test with the CodeRush, do the following.

  1. Create a new class file.
  2. Reference the required test framework (for instance, NUnit installed from NuGet).
  3. Delete the auto-generated class definition.
  4. Expand the t template within the namespace.

Show animation

Templates_Test_New

The t template expanded outside the class corresponds to the tc (test class) or tf (test fixture) template. If you expand the t template inside the class, it will call the tm (test method) template that creates a new test method.

Show animation

Templates_Test_Method

Adding Assertions

Templates for the most common assertions are presented in the table below. To see the full list, use the CodeRush | Code Templates... menu item.

Template Description
ae Assert Equality
as Assert the Same
ans Assert Not the Same
at Assert True
af Assert False
an Assert Null
ann Assert Not Null

Show animation

Templates_Test_Asstert

Note

The exact set of templates depends on the testing framework. To see the full list, refer to the Testing category in the Editor | All Languages | Templates options page. To quickly access this options page, use the CodeRush | Code Templates... menu item.

See Also