Visual Studio xUnit TestMethod Snippet

A snippet that scaffolds a Fact Testmethod.
Add the snipper to Visual Studio, in a .cs file type xTest (the shortcut) and press tab twice.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>xUnit Fact Method</Title>
			<Shortcut>xTest</Shortcut>
			<Description>Code snippet for creating a Test Method with xUnit</Description>
			<Author>Ben Beckers</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>UnitOfWork</ID>
					<ToolTip>The name of the Method to test on the SUT</ToolTip>
					<Default>UnitOfWork</Default>
				</Literal>
				<Literal>
					<ID>StateUnderTest</ID>
					<ToolTip>Valid or invalid or null,...</ToolTip>
					<Default>StateUnderTest</Default>
				</Literal>
				<Literal>
					<ID>ExpectedBehavior</ID>
					<ToolTip>What the outcome of the test should be</ToolTip>
					<Default>ExpectedBehavior</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[[Fact]
			public void $UnitOfWork$_$StateUnderTest$_$ExpectedBehavior$()
			{
				//Arrange.

				//Act.

				//Assert.
				Assert.True(false);
			}
			$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

Leave a Reply