Microsoft Fakes and TeamCity (and XUnit)

This post is a note to my future self on how to configure a TeamCity build to run tests that use Microsoft Fakes. If you haven’t ever come across Microsoft Fakes then take a look at this post – Testing the untestable with Microsoft Fakes (http://msmvps.com/blogs/bsonnino/archive/2013/08/11/testing-the-untestable-with-microsoft-fakes.aspx) for a good introduction.

Setting up the Build Agent

You will need to install Visual Studio 2012 and make sure that Update 3 is applied, no additional installation is required as Microsoft Fakes comes bundled.

If your tests are written using XUnit, which in my case they were then the next step is very important, (if you are using MSTest then you can skip this step and go to Configuring the Build Step).

You will then need to logon to the build agent machine with the user that the build agent runs as (i.e. not you!). Once logged on, launch Visual Studio and install the XUnit test runner. The reason for this is that Visual Studio extensions are installed per user. This caught me out!

Next up, you will need to download the TeamCity vstest logger from GitHub (https://github.com/nickers/vstest.teamcity.logger), build this and follow the instructions from the project page as to where the built DLL needs to go.

At this point, everything on the build server is setup and it is time to configure the TeamCity project.

Configuring the Build Step

Go into the setup of your project and add a new Build step.

Runner type: Command line

Step name: <can be whatever you like>

Execute step: Only if all previous steps were successful

Working directory: Set to the bin\Release (or bin\Debug) folder for your solution, depending on which one you are building/testing, this will most likely be Release

Run: Custom Script

Custom Script: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe myinsertingproject.tests.dll /logger:TeamCityLogger /UseVsixExtensions:true

Update 21/11/2013 –

Turns out you do need to set the working directory, also updated the custom script to include the full path to the vstest.console.exe (thanks to @kevindrouvin)

Summary and Resources

That should be all you need to do to get the tests running and being reported back into TeamCity. Depending on how your environment path is setup you might need to give the directory to the vstest.console.exe in the Custom Script setup.

Here are a few different resources that I used:

Advertisements

One thought on “Microsoft Fakes and TeamCity (and XUnit)

  1. d says:

    Very helpful, thank you. No way I would have figured this out on my own and I couldn’t find anything on the subject on the jetbrains website or anywhere else. I’m a little surprised that this workaround is even necessary but at least it exists.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s