运行 NUnit 并指定类别时,是否也可以包含所有未分类的测试?

发布于 2024-09-25 00:29:14 字数 884 浏览 1 评论 0原文

我们有数百个测试类,其中几十个测试类标记有以下属性: [测试治具] [明确] [类别(“集成测试”)] 因此它们只会在我们通宵自动构建中运行。其余的 TestFixtures 没有指定类别(也没有标记为显式)。

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

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

当然,这不会执行任何未分类的测试。

我希望能够做这样的事情:

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

所有未分类的测试将与集成测试一起运行。这可能吗?如果是这样,语法是什么?

(注意:我正在寻找如上所述的 NAnt 解决方案,或者 NUnit 命令行解决方案。我当然可以使用不同的选项运行 NUnit 两次,或者将类别放在我的所有 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).

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2024-10-02 00:29:14

我也遇到了同样的情况,并且一直感到沮丧,直到我发现类别属性不仅可以应用于测试或测试夹具,还可以应用于整个程序集。

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

当我在前两个项目上本地运行 NUnit 时,我只需在各个程序集上运行它,根本不需要指定类别。

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.

ゞ花落谁相伴 2024-10-02 00:29:14

不,鉴于您的情况,无法在单次运行 NUnit 中完成您想要的操作。如果您取消了显式属性,则可以通过排除所有不需要的分类测试来在一次运行中完成此操作。

基本上,如果您跳转到类别,则所有测试都应该进行分类。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文