Continuous Integration with Jenkins and MSTest

I have just set up CI with Jenkins for a client. I will now demonstrate how I did this. I will create a demo MVC project that basically does nothing in the browser. It does however have some unit tests in it that test some very simple business logic using Moq.
Here is my sample MVC4 project and then tests:

The unit tests within my project. You can see that they just test some arbitrary business logic and mock out a repository but it doesn’t matter what they really do as this post is about making Jenkins run MSTests.
Now I want to get Jenkins to:

  • poll my SVN server to check for new commits.
  • Build the code
  • Run my 2 unit tests
  • Create a unit test report
  • Send the report to email recipients.

Ok so first we want set up Jenkins.
I needed to install the following first as MSTest was not available:
Visual Studio Agents – ISO:
There are some config options with this but I just used the defaults and it all worked just fine.
Following that I began setting up Jenkins.
Here is my Jenkins project name:

Now we want to set up polling (currently 15 minutes). If an SVN commit is detected Jenkins will begin running a build. 

Then we need to point to our solution file for the build to work:
We then need to point to our unit testing DLL so Jenkins can tell MSTest where our tests are:
Then we need to tell a 3rd part tool (you don’t have to use this tool) to convert our trx file to Html format so it is easier to read:
After that, we want to ensure we actually publish our trx file:
And then set up email notifications to tell us when certain thing occur like the build failing:
We can then run the build:
After the build output we can now see the MSTest output:
If we now look in the file system we can see the original trx file and the newly generate Html version:
When we look at the Html we can see a nice summary of our passing test:
And if we force the tests to fail we can see this also:

You can also look at the build trends in Jenkins and see what’s been happening:

And drill down on these:

That’s all there is to it. I have been meaning to set this up for ages and finally got the opportunity to do it.
Ps. Waiting on another Jenkins Plugin to be installed so I can email the Html version of the trx report to email recipients.