Bradley Braithwaite
1 import {
2 Learning,
3 JavaScript,
4 AngularJS
5 } from 'Brad on'
6 |
Check out my online course: AngularJS Unit Testing in-depth with ngMock.

Use MSTest? Then do this!

on tools, MSTest

If like me you write a lot of unit test using Visual Studio then I hope that you make use of the snippet for creating a new test method? If not, then I forgive you and the shortcut is:

Ctrl + K, Ctrl + X

You will see the snippets menu and you can select:


This saves some typing as you get an empty method template:

New method copy

If you layout your tests as I do using the Arrange, Act, Assert structure then we still have to type this out each time. In order to save my valuable keystrokes I created my own snippet file that inserts the AAA structure as standard. Simply download the following XML file and save this file in the same folder as the standard Visual Studio snippets for tests. On my machine this is:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Test

To check this has worked select:

Ctrl + K, Ctrl + B (Tools > Code Snippets Manager)

You should see the new snippet (Test Method with AAA) along with the default snippets:

Screen Shot 2012 11 28 at 16 52 41

Now when we repeat the insert snippet command we choose our new snippet and we get the following code template:


Much better! Here is the snippet xml file:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="">
<CodeSnippet Format="1.0.0">
<Title>Test Method with AAA</Title>
<Description>Code snippet for a test method</Description>
<ToolTip>Replace with the name of the test method</ToolTip>
<Literal Editable="false">
<Code Language="csharp">
public void $name$()
// Arrange

// Act

// Assert


Download the raw xml file from this Github gist.

Don't miss out on the free technical content:

Subscribe to Updates


Bradley Braithwaite Software Blog Bradley Braithwaite is a software engineer who works for search engine start-ups. He is a published author at He writes about software development practices, JavaScript, AngularJS and Node.js via his website . Find out more about Brad. Find him via:
You might also like:
mean stack tutorial AngularJS Testing - Unit Testing Tutorials