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

荒凉一梦 提交于 2020-01-01 09:38:11

问题


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.)


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3791088/when-running-nunit-and-specifying-a-category-can-all-uncategorized-tests-be-inc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!