Creating a visual studio Arrange-Act-Assert snippet

Posted : Thursday, 06 December 2012 10:44:00

First things first I’m big on unit testing, I love it! From the time I read this book The Art of Unit Testing I was sold. If anyone reading this wants to know more about unit testing this book is the place to start.

Anyway, I find myself writing a lot of tests (generally using MsTest but that’s purely out of laziness) and while the standard snippet that comes with Visual Studio is ok, its not quite what I want. After reading the above book I like to structure my tests using the skeleton below:


public void Method_Scenario_Expectation()






Creating tests using the built in Visual Studio snippet is better than nothing but then I have to make the same alterations every time, namely changing the method name and adding the Arrange,Act,Assert comments. Recently I decided to try and create a snippet to do this for me and it was alarmingly easy. I found a few blog posts on the subject and its quite a simple process so rather than go over the whole thing – I’ve just included the snippet below.

<?xml version="1.0" encoding="utf-8"?>



  <CodeSnippet Format="1.0.0">


      <Title>MsTest unit test snippet</Title>

      <Author>Dave Lowe</Author>

      <Description>Adds a unit test stub method for MsTest</Description>





        <Literal Editable="true">


          <ToolTip>name of method under test</ToolTip>




        <Literal Editable="true">


          <ToolTip>scenario under test</ToolTip>


  • (This will not appear on the site)