RSS Feed

NUnit Test Visual Studio Snippet

I am using NUnit framework to write Unit Tests. To simplify my work I have a simple snippet which generates test method.

[Test]
public void TestName()
{
#region Arrange
#endregion 

#region Act

Assert.Fail();

#endregion

#region Assert
#endregion
}

As you can see there are regions for different actions.

Here is a code for this snippet. If you want to use it. Just copy paste it to the xml file and name it with extensions “*.snippet”. Then in Visual Studio go to (Tools –> Code Snippet Manager) and import this file.

<CodeSnippets
xmlns=http://schemas.microsoft.com/VisualStudio/2010/CodeSnippet&#8221;>
<CodeSnippet Format=“1.0.0”>
<Header>
<Title>
NUnit Test
</Title>
</Header> 

<Snippet>
<Declarations>
<Literal>
<ID>TestName</ID>
<ToolTip>Replace with TestName.</ToolTip>
<Default>TestName</Default>
</Literal>
</Declarations>
<Code Language=“CSharp”>
<![CDATA[
[Test]
public void $TestName$()
{
#region Arrange
#endregion

#region Act

Assert.Fail();

#endregion

#region Assert
#endregion
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s