在运行NUnit并指定类别时,是否也可以包括所有未分类的测试? [英] When running NUnit and specifying a category, can all uncategorized tests be included too?

查看:100
本文介绍了在运行NUnit并指定类别时,是否也可以包括所有未分类的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有数百个测试类,其中有几十个带有以下属性的标记: [TestFixture] [明确] [Category("IntegrationTests")] 因此它们只能在我们的通宵自动化版本中运行.其余的TestFixture没有指定类别(也未标记为显式").

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

这是我们正在运行以执行测试的NAnt任务:

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?

(注意:我正在寻找如上所述的NAnt解决方案,或者NUnit命令行解决方案.我当然可以使用不同的选项运行NUnit两次,或者将Category放在我的所有TestFixture上.这些都是解决方法如果可以的话,我可以使用,但是能够直接指定未分类的测试会更酷.)

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

推荐答案

我在同一条船上,并感到沮丧,直到我发现Category属性不仅可以应用于测试或测试治具,而且可以应用于整个装配.

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.

我有两个带有在本地运行的测试的测试程序集,还有一个带有仅应在构建服务器上运行的测试的测试程序集.我在前两个项目中的AssemblyInfo.cs中添加了此属性:[assembly: NUnit.Framework.Category("Always")].第三个测试项目使用您所描述的类别服装,例如[Explicit, Category("PublicDatabase")].构建服务器使用/include=Always,PublicDatabase调用NUnit并获得所需的结果:前两个程序集中的所有测试都将运行,而第三个程序集中的PublicDatabase测试仅将运行.

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.

当我在前两个项目中本地运行NUnit时,我只在单个程序集上运行它,根本不必指定类别.

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.

这篇关于在运行NUnit并指定类别时,是否也可以包括所有未分类的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆