Code Templates – NUnit testing
May 17th, 2011
Just a list of NUnit-testing CodeRush code templates useful for test-driven development. Bear in mind, if you have an identifier on the Clipboard, assert templates will automatically paste the identifier from the Clipboard as an argument to the assert call. The meaning of the text commands in bold can be seen in the corresponding topic.
CSharp templates:
Template |
Expansion |
tc or tf | [TestFixture] public class «Caret»«Field(Tests)»«BlockAnchor» { [Test] public void «Field(Test)»() { «Target» } } |
tfsu | [TestFixtureSetUp] public void InitializeAllTests() { «Caret»«Marker» } |
tftd | [TestFixtureTearDown] public void CleanupAllTests() { «Caret»«Marker» } |
tm | [Test] public void «Caret»«Field(Test)»«BlockAnchor» () { «Target» } |
tsu | [SetUp] public void Setup() { «Caret»«Marker» } |
ttd | [TearDown] public void TearDown() { «Caret»«Marker» } |
Asserts |
|
as or aas | Assert.AreSame(«Caret» «Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)») |
ae | Assert.AreEqual(«Caret» «Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)») |
ae0 | Assert.AreEqual(0, «Caret»«?Paste»«BlockAnchor»); |
ae0 | Assert.AreEqual(0, «Caret»); |
ae1 | Assert.AreEqual(1, «Caret»«?Paste»«BlockAnchor»); |
ae1 | Assert.AreEqual(1, «Caret»); |
af | Assert.IsFalse(«Field»«Caret») |
afl | Assert.Fail(«Field»«Caret») |
ai | Assert.Ignore(«Field»«Caret») |
an | Assert.IsNull(«Field»«Caret») |
anae | Assert.AreNotApproximatelyEqual<«Caret» «Field(TValue)» «BlockAnchor», «Field(TDifference)»>( «Field(unexpected,Unexpected value)», «Field(actual,Actual value)», «Field(delta,Difference)»); |
ann | Assert.IsNotNull(«Field»«Caret») |
ans | Assert.AreNotSame(«Caret»«Field(unexpected,Unexpected value)»«BlockAnchor», «Field(actual,Actual value)»); |
at | Assert.IsTrue(«Field»«Caret») |
Attributes |
|
[ee | [ExpectedException(typeof(«Caret» NullReferenceException «BlockAnchor»))] |
[ia | [Ignore] |
[su | [SetUp] |
[t | [Test] |
[tc | [TestFixtureTearDown] |
[tc | [TestFixture] |
[td | [TearDown] |
[tf | [TestFixture] |
[tfsu | [TestFixtureSetUp] |
[tftd | [TestFixtureTearDown] |
[ti | [TestFixtureSetUp] |
[tm | [Test] |
Namespaces |
|
unf or unuf | using NUnit.Framework; |
Visual Basic templates:
Template |
Expansion |
tc or tf | <TestFixture> _ Public Class «Caret» «Field(Tests)» «BlockAnchor» <Test> _ Public Sub «Field(Test)»() «Target» End Sub End Class |
tfsu | <TestFixtureSetUp> _ Public Sub InitializeAllTests() «Caret»«Marker» End Sub |
tftd | <TestFixtureTearDown> _ Public Sub TestFixtureTearDown() «Caret»«Marker» End Sub |
tm | <Test> _ Public Sub «Caret»«Field(Test)»«BlockAnchor»() «Target» End Sub |
tsu | <SetUp> _ Public Sub SetUp() «Caret»«Marker» End Sub |
ttd | <TearDown> _ Public Sub TearDown() «Caret»«Marker» End Sub |
Attributes |
|
as or aas | Assert.AreSame(«Caret»«Field(expected,Expected value)»«BlockAnchor», «Field(actual,Actual value)») |
ae | Assert.AreEqual(«Caret»«Field(expected,Expected value)»«BlockAnchor», «Field(actual,Actual value)») |
ae0 | Assert.AreEqual(0, «Caret») |
ae1 | Assert.AreEqual(1, «Caret») |
af | Assert.IsFalse(«Caret») |
afl | Assert.Fail(«Caret») |
ai | Assert.Ignore(«Caret») |
an | Assert.IsNull(«Caret») |
ann | Assert.IsNotNull(«Caret») |
at | Assert.IsTrue(«Caret») |
Attributes |
|
<ia | <Ignore(“«Caret»“)> |
<su | <SetUp> |
<t | <Test> |
<tc | <TestFixtureTearDown> |
<tc | <TestFixture> |
<td | <TearDown> |
<tf | <TestFixture> |
<tfsu | <TestFixtureSetUp> |
<tftd | <TestFixtureTearDown> |
<ti | <TestFixtureSetUp> |
<tm | <Test> |
Namespaces |
|
inf or inuf | Imports NUnit.Framework |