Skip to content

Instantly share code, notes, and snippets.

@MisterJames
Last active December 9, 2020 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MisterJames/4732853 to your computer and use it in GitHub Desktop.
Save MisterJames/4732853 to your computer and use it in GitHub Desktop.
This is a code snippet that you can invoke via tab completion. Type aaa and get a full test method with Arrange, Act, Assert parts, with encouragement to help name your test method following Roy Osherove's lead (http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html).
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>AAA Test Method</Title>
<Shortcut>aaa</Shortcut>
<Description>Code snippet for a test method with Arrange, Act, Assert</Description>
<Author>James Chambers</Author>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>Microsoft.VisualStudio.TestTools.UnitTesting</Namespace>
</Import>
</Imports>
<References>
<Reference>
<Assembly>Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</Assembly>
</Reference>
</References>
<Declarations>
<Literal>
<ID>MethodName</ID>
<ToolTip>The name of the method under test</ToolTip>
<Default>Method</Default>
</Literal>
<Literal>
<ID>StateUnderTest</ID>
<ToolTip>Specific contditions that lead to expected result</ToolTip>
<Default>State</Default>
</Literal>
<Literal>
<ID>ExpectedBehavior</ID>
<ToolTip>The expected result of the given state when the method is invoked</ToolTip>
<Default>Expectations</Default>
</Literal>
<Literal Editable="false">
<ID>TestMethod</ID>
<Function>SimpleTypeName(global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod)</Function>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[[$TestMethod$]
public void $MethodName$_$StateUnderTest$_$ExpectedBehavior$()
{
// Arrange
$end$
// Act
// Assert
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
@VatsikDimon
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment