Act Arrange Assert Comment Snippet

When I write unit tests, I like to quickly add the following commenting or scaffolding:

[TestMethod]
public void NameOfTestMethod()
{
	//  Arrange

	//  Act

	//  Assert     
}

As I’m always on the lookout to streamline my workflows, I created a Visual Studio snippet for that commenting. The text of the snippet is:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 <CodeSnippet Format="1.0.0">
  <Header>
   <Title>Act Arrange Assert</Title>
   <Shortcut>aaa</Shortcut>
   <Description>Code snippet for Act, Arrange Assert text.</Description>
   <Author>Dave</Author>
  </Header>
  <Snippet>
   <Code Language="csharp"><![CDATA[//  Arrange

            //  Act

            //  Assert                        
		]]>
   </Code>
  </Snippet>
 </CodeSnippet>
</CodeSnippets>

There’s a couple of ways of installing that snippet:

  1. Copy that text into a text editor and save it as a file with the snippet file extension into the relevant directory for snippets in your environment (I called mine aaa.snippet) . For me, that was
    E:\Documents\Dave\Documents\Visual Studio 2013\Code Snippets\Visual C#\My Code Snippets
  2. Open the Code Snippets Manager (Tools > Code Snippets Manager) and import it via that GUI:

    CodeSnippetsManager

To use the snippet, you just type the letters aaa then immediately hit the tab key twice. Also, you will need to restart Visual Studio (if it was already open when you saved the snippet).

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>