Skip to main content
A newer version of this page is available. .

Templates for Unit Tests

This topic describes integrated templates that simplify writing unit tests.

CodeRush supports the following test frameworks:

  • MbUnit
  • MSTest
  • NUnit
  • xUnit

Create Test Fixtures and Test Methods

Follow the steps below to write a test with CodeRush.

  1. Create a new class file.
  2. Reference the 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 tf (test fixture) template. If you expand the t template inside the class, it calls the tm (test method) template that creates a new test method.

Show animation

Templates_Test_Method

Add Assertions

The table below shows templates for the most common assertions.

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

The 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. Use the CodeRush | Code Templates... menu item to access this options page.

Templates_Test_Asstert

See Also