Skip to main content

Templates for Unit Tests

  • 2 minutes to read

This topic describes integrated templates that simplify writing unit tests.

Important

Visual Studio IntelliSense has priority over CodeRush templates. For information on how to prioritize a CodeRush template over Visual Studio IntelliSense, refer to the following topic section: Expand a Template Instead of Visual Studio IntelliSense.

CodeRush supports the following test frameworks:

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

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.

#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

#Example

The screencast below shows the “ae” template expansion.

#Template Configuration

The set of templates depends on the testing framework. To see the full template 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