gpt4 book ai didi

.net - NUnit 类别组合?

转载 作者:行者123 更新时间:2023-12-03 11:35:08 25 4
gpt4 key购买 nike

在我的 NUnit testfixtrues 中,我有一些类似的东西

[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 个测试。

有什么方法可以将此行为更改为 AND 条件而不是 OR ?

我目前正在运行 v2.5.0.9122。

提前致谢。

最佳答案

2019 年 NUnit 3.0 的快速答案。
可以使用多个类别。

考虑以下示例:


[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);
}
}


您可以运行两个类别的测试 AB并排除类别 C使用此命令参数: --where="cat==A && cat==B && cat!=C"
enter image description here

或者您可以使用任何类别运行测试 AB不包括 C像这样: --where="(cat==A || cat==B) && cat!=C"
enter image description here

关于.net - NUnit 类别组合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1199611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com