NUnit类别组合在一起吗? [英] NUnit Categories in combination?

查看:46
本文介绍了NUnit类别组合在一起吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的NUnit testfixtrue中,我有类似的东西

In my NUnit testfixtrues i have something along the lines of

[Test,Category("catA")]
public void test1
{
    //
}

[Test,Category("catB")]
public void test2
{
    //
}

[Test,Category("catA")]
[Test,Category("catB")]
public void test3
{
    //
}

现在在NUnit gui中,我希望能够选择catA和catB并在存在catA catB的地方运行测试.当前不是这种情况,NUnit将运行所有3个测试.

Now in the NUnit gui i want to be able to select catA and catB and run the tests where catA and catB are present. Currently this is not the case and NUnit will run all 3 tests.

是否可以将这种行为更改为AND条件而不是OR?

Is there any way to change this behavior to an AND condition rather than OR?

我当前正在运行v2.5.0.9122.

I'm currently running v2.5.0.9122.

谢谢.

推荐答案

NUnit 3.0从2019年起的快速解答.可以使用多个类别.

The quick answer from 2019 for NUnit 3.0. It's possible to use multiple categories.

请考虑以下示例:


    [TestFixture]
    public class Tests1
    {
        [Test]
        [Category("A")]
        public void TestA()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }

        [Test]
        [Category("B")]
        public void TestB()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }

        [Test]
        [Category("C")]
        public void TestC()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }

        [Test]
        [Category("A")]
        [Category("B")]
        public void TestAB()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }

        [Test]
        [Category("A")]
        [Category("C")]
        public void TestAC()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }

        [Test]
        [Category("B")]
        [Category("C")]
        public void TestBC()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }

        [Test]
        [Category("A")]
        [Category("B")]
        [Category("C")]
        public void TestABC()
        {
            Console.WriteLine(TestContext.CurrentContext.Test.Name);
        }
    }

您可以使用以下命令参数同时对类别 A B 进行测试,并排除类别 C .="cat == A&& cat == B&& cat!= C"

You can run the tests with both categories A and B and excluding category C using this command argument: --where="cat==A && cat==B && cat!=C"

或者您可以使用类别 A B 中的任何类别运行测试,并排除 C 这样的类别:-where =((cat == A || cat == B)&& cat!= C"

Or you can run the tests with any of categories A and B and excluding C like this: --where="(cat==A || cat==B) && cat!=C"

这篇关于NUnit类别组合在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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