all Technical posts

Continuous Integration with JavaScript, NUnit on TFSBuild (Part 3/3)

At Codit Products we often do research at new technologies. It is important that these new technologies are easy to use, testable and maintainable. I would like to share my experience about JavaScript testing on a continuous Team Foundation Build server.

In this blog series, we first focus on how to automatically test and get code coverage from JavaScript. Part 2 describes how to execute javascript tests on the build server and have test results next to your build package. Part 3 explains how to use other testing frameworks like NUnit instead of the default MSTest framework on the build server.

For earlier blog posts in this series, see part 1 or part 2.

Setting up NUnit for TFSBuild

Read this if you are using an existing build controller:

Previous Test Adapters needed to be installed as custom dll’s (Version control custom assemblies on your build controller). This is not needed anymore, you can just add the test adapter as a nuget package to your test project. However, if you have custom assemblies, they take precedence over the nuget package dll’s, so it’s recommended that you check this folder for older versions.

Single test project

Install the following NuGet package: NUnit TestAdapter including NUnit 2.6.3 framework 1.2.0.

Multiple test projects

Install the following NuGet package on each test project: NUnit v2.6.4 And install the adapter on 1 random test project NUnitTestAdapter v1.2.0

We’re using Nunit because it has “better” support than other frameworks like XUnit on TFSBuild.

Running tests for a specific category

Each unit test framework has a different way of grouping Unit tests in categories (MSTest uses “TestCategory”, Nunit uses “Category”, XUnit uses “Traits”, Chutzpah uses “Module”, …). Some test frameworks have adapters available that map the TFS Build properties to the properties used by your framework. However, In my experience, they only work for NUnit (and of course MSTest).

On TFS Build when you create a new build definition you can specify what test category to use by filling the “Test case filter”. This filter uses the following syntax: “TestCategory=CategoryName”. There are 4 filter expression keys that you can use: “FullyQualifiedName, Name, Priority, TestCategory” and you can specify multiple by using the pipe character (ex: “TestCategory=Unit|TestCategory!=Acceptance”).

Category _test

Category _test2

Running tests with code coverage

Change your the build definition to have CodeCoverageEnabled enabled

Code _coverage _enabled

When we run our build, we get the following result:

Code _coverage _result (1)

When you click on “Coverage Result” on the successful build, you can download the Code Coverage file. This file needs to be opened in Visual Studio. You can then have a detailed view of the coverage. If you double click a tree node, you see the actual code fragment that was covered (it’s highlighted in blue).

Code _coverage _highlight

In the last part of this blogseries we have discussed how to use another framework than MSTest to run our tests on TFSBuild. We see that it’s not only MSTest that delivers support for TestCategories and Code Coverage but you could use another framework like NUnit too.

Sample Solution Files:

Download [22.5 MB]

Subscribe to our RSS feed

Thanks, we've sent the link to your inbox

Invalid email address

Submit

Your download should start shortly!

Stay in Touch - Subscribe to Our Newsletter

Keep up to date with industry trends, events and the latest customer stories

Invalid email address

Submit

Great you’re on the list!