When running NUnit and specifying a category, can all uncategorized tests be included too?
Asked Answered
L

2

7

We have several hundred test classes, with a few dozen of them marked with the following attributes: [TestFixture] [Explicit] [Category("IntegrationTests")] so they will only be run in our over-night automated build. The remaining TestFixtures don't have a Category specified (and are not marked Explicit either).

Here is the NAnt task we are running to execute our tests:

<nunit2>
    <test>
        ...
        <categories>
            <include name="IntegrationTests" />
        </categories>
        ...
    </test>
</nunit2>

This, of course, will not execute any of the uncategorized tests.

I'd like to be able to do something like this:

<nunit2>
    <test>
        ...
        <categories>
            <include name="*" />
            <include name="IntegrationTests" />
        </categories>
        ...
    </test>
</nunit2>

where all of the uncategorized tests will be run along with the integration tests. Is this possible? If so, what is the syntax?

(Note: I'm looking for either a NAnt solution, as above, or an NUnit command-line solution. I can certainly run NUnit twice with different options, or put Categories on all of my TestFixtures. These are workarounds that I'm OK using if I have to, but it would be more cool to be able to specify uncategorized tests directly.)

Learnt answered 24/9, 2010 at 21:19 Comment(0)
C
9

I'm in the same boat, and was getting frustrated until I just discovered that the Category attribute can be applied not just to a test or test fixture, but to a whole assembly.

I have two test assemblies with tests that I run locally, and one more with tests that should only run on the build server. I added this attribute in AssemblyInfo.cs in the first two projects : [assembly: NUnit.Framework.Category("Always")]. The third test project uses category attibutes like [Explicit, Category("PublicDatabase")] as you describe. The build server invokes NUnit with /include=Always,PublicDatabase and has the desired result: all of the tests in the first two assemblies run, and just the PublicDatabase tests in the third assembly run.

When I run NUnit locally on the first two projects, I just run it on the individual assemblies, and don't have to specify categories at all.

Capful answered 1/11, 2010 at 22:1 Comment(1)
IIUC, this won't just run "all uncategorized tests as well". It will run all tests as well (from the assembly that has the assembly level category), including any tests in there that have an explicit category (I'm assuming categories are additive)?Addlebrained
A
0

No, given you situation there is no way to do what you want in a single run of NUnit. If you took off the explicit attribute, you could do it in a single run by excluding all the categorized tests you don't want.

Basically, if you make the jump to categories, all you tests should be categorized.

Anglican answered 20/10, 2010 at 21:34 Comment(1)
I'd be fine with that if there's a way to ensure that all tests are categorized?Addlebrained

© 2022 - 2024 — McMap. All rights reserved.