← All articles
development

Excluding Integration Tests from your Automated Build

How to tag tests as Integration and exclude them from your CruiseControl.NET build using NUnit categories and the NAnt NUnit2 task.

Donn Felker

Donn Felker

2009.02.09 · 1 min read · updated July 5, 2013

A simple tip to exclude certain tests from running during your automated build.

In this scenario we have a bunch of tests inside of a particular DLL. Inside of these tests we have a folder that is for “integration tests”. These tests are run usually once a day in a nightly build and are also run on a developers machine to ensure they didn’t break anything from an integration standpoint before checking in the code.

What we want to do is exclude the tests from running in our CC.NET continuous integration build environment. This is real simple to do by just following a couple of simple steps.

  1. Categorize your tests as “Integration” (or whatever you want to call them). I prefer “integration” because it signifies exactly what  they are.
  2. Exclude them via the NUnit2 task in the NAnt build script.

Example code:

[TestFixture, Category("Integration")]
public class OrderServiceIntegraitonTests
{
// a slew of tests go here ...
}

Then in your NAnt file do something similar to the following to ensure these tests are excluded for the continuous integration build:

<nunit2 failonerror="true" >
<formatter type="Xml" outputdir="${results.dir}" usefile="true" extension=".xml"/>
<formatter type="${outputType}" usefile="false"/>
<test assemblyname="${out.dir}/DF.Example.Tests.dll">
<categories>
<exclude name="Integration" />
</categories>
</test>
</nunit2>

That’s it. By using the exclude element in the NUnit2 task in NAnt you can exclude them.

This is also a command line switch as well, so if you’re not running them in NAnt you can also exclude them via the command line switch, /exclude.

Donn Felker

Written by Donn Felker

I've spent 25+ years shipping software, writing books, and running my own companies. I write about thinking clearly, working for yourself, and doing real work while AI rewrites the rules. New essays land here every week.

Get the newsletter

Keep reading