Home > Code Generation, Testing > Code Templates – NUnit testing

Code Templates – NUnit testing

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 aasAssert.AreSame(«Caret» «Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)
aeAssert.AreEqual(«Caret» «Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)
ae0Assert.AreEqual(0, «Caret»«?Paste»«BlockAnchor»);
ae0Assert.AreEqual(0, «Caret»);
ae1Assert.AreEqual(1, «Caret»«?Paste»«BlockAnchor»);
ae1Assert.AreEqual(1, «Caret»);
afAssert.IsFalse(«Field»«Caret»)
aflAssert.Fail(«Field»«Caret»)
aiAssert.Ignore(«Field»«Caret»)
anAssert.IsNull(«Field»«Caret»)
anaeAssert.AreNotApproximatelyEqual<«Caret» «Field(TValue)» «BlockAnchor», «Field(TDifference>( «Field(unexpected,Unexpected value, «Field(actual,Actual value, «Field(delta,Difference);
annAssert.IsNotNull(«Field»«Caret»)
ansAssert.AreNotSame(«Caret»«Field(unexpected,Unexpected value)»«BlockAnchor», «Field(actual,Actual value);
atAssert.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 unufusing 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 aasAssert.AreSame(«Caret»«Field(expected,Expected value)»«BlockAnchor», «Field(actual,Actual value)
aeAssert.AreEqual(«Caret»«Field(expected,Expected value)»«BlockAnchor», «Field(actual,Actual value)
ae0Assert.AreEqual(0, «Caret»)
ae1Assert.AreEqual(1, «Caret»)
afAssert.IsFalse(«Caret»)
aflAssert.Fail(«Caret»)
aiAssert.Ignore(«Caret»)
anAssert.IsNull(«Caret»)
annAssert.IsNotNull(«Caret»)
atAssert.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 inufImports NUnit.Framework
—–
Products: CodeRush Pro
Versions: 10.2 and up
VS IDEs: any
Updated: May/18/2011
ID: C099

Similar Posts:

  1. No comments yet. Be the first and leave a comment!
  1. No trackbacks yet.