There’s a lot of cool things that you can do with nAnt, like running your tests against NUnit or another unit testing framework. Let’s pretend we already have a target called “compile” that will compile our application into an assembly into the build folder. See…
We can create a new target that will compile our test project(s) into a single test assembly and save it to our build folder, where we saved our application assembly. The following target will recurse through a subdirectory called “test” and compile all files with a .cs extension into our test assembly.
The references element allows us to include other assemblies that our test assembly depends on. In the above case I’m using NUnit, and RhinoMocks. Our test assembly also depends on the application assembly, after all that is what our tests are supposed to be testing.
So far we have compiled our application assembly and test assembly, and saved them to the same directory called build. Now lets create a target that will run our unit tests using the nunit-console.exe.
The above target will copy over the Rhino.Mocks.dll, and NUnit dlls into our build folder. Then execute “nunit-console.exe” from the command line and pass it in the path to our test assembly, and will tell it what to name the xml file that nunit will spit out with the test results.
As you can see the test results are also shown to the console window. As you can see, I have run 8 tests, with 3 failures. (Looks like I’ve made a breaking change!)