Skip to content

Instantly share code, notes, and snippets.

@Guzzter
Forked from marcduiker/xunit_fact.snippet
Created March 1, 2019 08:40
Show Gist options
  • Save Guzzter/8b43e1c81ecd8b50ce1e44b8b177ad09 to your computer and use it in GitHub Desktop.
Save Guzzter/8b43e1c81ecd8b50ce1e44b8b177ad09 to your computer and use it in GitHub Desktop.
Visual Studio C# snippet for xUnit test methods (Facts) using the naming convention proposed by http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html. Import the snippet using the SnippetManager in VS and type `fact[tab][tab]` inside a class to insert the snippet.
<?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>xUnit Fact</Title>
<Shortcut>fact</Shortcut>
<Description>Code snippet for an xUnit test method (Fact) following the naming convention UnitOfWork_StateUnderTest_ExpectedBehaviour.</Description>
<Author>Marc Duiker</Author>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>Xunit</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>UnitOfWork</ID>
<ToolTip>Describe the unit that will be tested.</ToolTip>
<Default>UnitOfWork</Default>
</Literal>
<Literal>
<ID>StateUnderTest</ID>
<ToolTip>Describe the initial state or preconditions.</ToolTip>
<Default>StateUnderTest</Default>
</Literal>
<Literal>
<ID>ExpectedBehaviour</ID>
<ToolTip>Describe the expected behaviour or outcome.</ToolTip>
<Default>ExpectedBehaviour</Default>
</Literal>
<Literal Editable="false">
<ID>Fact</ID>
<Function>SimpleTypeName(Fact)</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[[$Fact$]
public void $UnitOfWork$_$StateUnderTest$_$ExpectedBehaviour$()
{
// Arrange
$end$
// Act
// Assert
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment