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.
- Create a new class file.
- Reference the test framework (for instance, NUnit installed from NuGet).
- Delete the auto-generated class definition.
- Expand the t template within the namespace.
Show animation
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
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
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.
See Also