Vla*_*irs 3 c# arrays nunit sequential
我如何将string[][]数组传递给ValuesAttribute?
我有:
public string[][] Array1 = new[] {new[] {"test1", "test2"}};
//...
[Test, Sequential]
public void SomeTest(
[Values("val1", "val2", "val3")] string param1,
[Values(Array1, Array2, Array3)] string[][] param2) { //... }
Run Code Online (Sandbox Code Playgroud)
而且我有Cannot access non-static field "Array1" in static context.比我标志着Array1与static关键字和比我有An attribute argument must be a constant expression...比我将其标记readonly关键字,仍然有我An attribute argument must be a constant expression...
有没有办法传递多个数组?(除丑陋string[][][]和传球param2的相关指标array[][]中array[][][])
有可能的.但是你需要使用TestCaseSourceAttribute而不是Sequential和Values.
看一个例子:
object[][] testCases = new[] {
// test case 1
new object[] {
"val1",
new[] { "test11", "test12" }
},
// test case 2
new object[] {
"val2",
new[] { "test21", "test22" }
},
// test case 3
new object[] {
"val3",
new[] { "test31", "test32", "test33", "test34" }
}
};
[Test]
[TestCaseSource("testCases")]
public void SomeTest(string param1, string[] param2)
{
...
}
Run Code Online (Sandbox Code Playgroud)
这里的另一个好处是:测试用例组织得更好,可以在多个测试中轻松重用.