nant: Custom messages for separate unit tests in single nant nunit2 target

59 views Asked by At

We are using nant to build our source code and run unit tests (nunit 2.5). In nant build file, we have separate nunit2 targets for different unit test assemblies.

<each message="Run Test 1" />
<nunit2 verbose="true">
    <formatter type="Plain" />
    <test assemblyname="Test1.dll" />
</nunit2>

<each message="Run Test 2" />
<nunit2 verbose="true">
    <formatter type="Plain" />
    <test assemblyname="Test2.dll" />
</nunit2>

On Team City build server it causes performance issue - each such target forces to load Nunit runner separately.

There is a possibility to merge tests in one nunit2 target:

<nunit2 verbose="true">
    <formatter type="Plain" />
    <test assemblyname="Test1.dll" />
    <test assemblyname="Test2.dll" />
</nunit2>

However, output in such case is not explicit enough for us without echo statements.

Is there a way to have one nunit2 target and specify custom messages for each test? Something like the following:

<nunit2 verbose="true">
    <formatter type="Plain" />
    <each message="Run Test 1" />
    <test assemblyname="Test1.dll" />
    <each message="Run Test 2" />
    <test assemblyname="Test2.dll" />
</nunit2>
1

There are 1 answers

0
Pylyp Lebediev On BEST ANSWER

The only way I found to have unit tests more verbose is to add labels attribute on nunit2 target

<nunit2 verbose="true" labels="true">
    <formatter type="Plain" />
    <test assemblyname="Test1.dll" />
    <test assemblyname="Test2.dll" />
</nunit2>

As a result, nant will output all run unit tests in the following format

***** Test1.Test1.Ctor_Test
***** Test2.Test2.Ctor_Test
Tests run: 2, Errors: 0, Failures: 0, Time: 0.123 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0