对于TestCase如何设置属性?

问题描述 投票:1回答:2

在NUnit中,我可以执行以下操作,然后从TestContext中检索ID

[Test]
[Property("ID", "HelloWorld")]
[Category("ABC")]

// TestContext.CurrentContext.Test.Properties.Get("ID").ToString() 
// --> HelloWorld

看起来不起作用的是下面的内容(当你在TestContext中查找ID时返回null)

[Category("ABCD")]
[TestCase("AZ", 1),Property("ID","a")]

同样的

[Category("ABCD")]
[TestCase("AZ", 1)]
[Property("ID","a")]

这甚至是可能的,还是我这么厚,我看不出正确的答案?

nunit-3.0
2个回答
1
投票

有趣的问题。我做了一个测试项目,你是对的。它不起作用。研究NUnits GitHub并且有一个开放的bug,大约存在三年:https://github.com/nunit/nunit/issues/1358

因此,NUnit的当前实现不允许将Property属性成功应用于TestCase。


0
投票

似乎有另一种配方。这是我以前从未见过的。我在这里找到了https://github.com/nunit/docs/wiki/TestCaseData的描述

[Test
public class ObjectPattern
{
    [TestCaseSource(typeof(ADataClass), "TestCases")]
    public int DivideTest(int n, int d)
    {
            ;
    }
}

public class ADataClass
{
    public static IEnumerable TestCases
    {
        get
        {
            yield return new TestCaseData(12, 3).setProperty("ID",4);
            yield return new TestCaseData(12, 2).setProperty("ID",4);
        }
    }  
}
© www.soinside.com 2019 - 2024. All rights reserved.