Posts Tagged ‘Code Snippet’

Nunit Code Snippet

Thursday, June 24th, 2010

Here is a useful code snippet that I use all the time to create an empty unit test.

To use it go to your My Code Snippets folder, go to the snippet manager in Visual Studio (Ctrl K + Ctrl B) to get the file path if you don’t know it. Create a new text file with and appropriate name and rename the extension to .snippet and cut and paste the following xml into the file and save it.

 

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>
                NUnit Test
            </Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>nunit.framework.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>Test_Name</ID>
                    <ToolTip>Replace with test method name</ToolTip>
                    <Default>Test_Name</Default>
                </Literal>
            </Declarations>
            <Code Language="CSharp">
            <![CDATA[]]>
            [Test]
            public void $Test_Name$()
            {
            }
            <![CDATA[]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets> 
 
And Bob’s your uncle it should appear in your code snippet shortcuts..Ctrl K Ctrl S to access.