问题
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