Wednesday, October 24, 2012

TFS 2012 Build: Configure NUnit to run your unit tests

With the release of Visual Studio and Team Foundation Server 2012, it becomes a lot easier to use other test frameworks than MS Test. Now it becomes possible to run NUnit, XUnit,… tests directly from Visual Studio using the same tooling and interface.

But how do you configure your build server to run these tests?
  1. Download the NUnit Test Adapter from the Visual Studio Gallery(http://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d).
  2. Install the adapter vsix on all your build servers.

    image

  3. Add the nunit.core.dll, nunit.core.interfaces.dll, nunit.util.dll and NUnit.VisualStudio.TestAdapter.dll to a folder in source control. Set this folder as the Version control path to custom assemblies. This can be managed by clicking “Manage Build Controllers” on the Build menu. Click on properties and set the correct path in version control.

    image

  4. Using VS 2012, edit your build definition, go to “Process”, click on “Test Source”, and then click on the ellipses to bring up the “Add/Edit Test Run” dialog box. In the “Test runner:” drop down, select “Visual Studio Test Runner”. This will use the new multi-framework compatible test runner that works with NUnit, MSTest, xUnit, and other testing frameworks.

    clip_image002

  5. That’s it!

3 comments:

Boja said...

Thanks for the great article! It was very helpful.

I was wondering if you could provide some knowledge regarding remote execution.

Currently we are using MSTest to remotely execute tests with a Test Controller and Test Agents. The .testSettings file configures how to run the tests (locally/ remote) and the name of the Test Controller Machine.

I'm currently looking into NUnit to replace MSTest. All is good locally. I Installed the Test Adapter and can discover and run tests locally using NUnit and Test Explorer.

But i couldn't find how to configure remote execution with NUnit and a Test Controller, as described above.

Couldn't find any clear documentation online regarding the subject, so any help will be much appreciated.

Rafael Fernandes said...

I have the same issue as Boja. It just returns the message:

Other Errors and Warnings
0 error(s), 1 warning(s)
No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

Rafael Fernandes said...

Turns out that you must install the adapter on each test project, if you miss this step it won't work.

please check the question on stackoverflow:
http://stackoverflow.com/questions/20027235/visual-studio-online-ci-nunit-tests-not-found-during-build/22329536#22329536