Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Nunit使用TestCaseSource运行TestCase,第一次迭代没有参数?为什么?_C#_Unit Testing_Nunit_Testcase_Testcasesource - Fatal编程技术网

C# Nunit使用TestCaseSource运行TestCase,第一次迭代没有参数?为什么?

C# Nunit使用TestCaseSource运行TestCase,第一次迭代没有参数?为什么?,c#,unit-testing,nunit,testcase,testcasesource,C#,Unit Testing,Nunit,Testcase,Testcasesource,嗨,我是Nunit的新手,我正在将一系列对象作为TestCaseSource传递给TestCase。出于某种原因,Nunit似乎在没有向其传递任何参数的情况下首先运行测试,这会导致忽略输出: 测试: private readonly object[] _nunitIsWeird = { new object[] {new List<string>{"one", "two", "three"}, 3}, new object[] {new List<string&

嗨,我是Nunit的新手,我正在将一系列对象作为TestCaseSource传递给TestCase。出于某种原因,Nunit似乎在没有向其传递任何参数的情况下首先运行测试,这会导致忽略输出:

测试:

private readonly object[] _nunitIsWeird =
{
    new object[] {new List<string>{"one", "two", "three"}, 3},
    new object[] {new List<string>{"one", "two"}, 2}

};

[TestCase, TestCaseSource("_nunitIsWeird")]
public void TheCountsAreCorrect(List<string> entries, int expectedCount)
{
    Assert.AreEqual(expectedCount,Calculations.countThese(entries));
}
private readonly object[]\u nunitiswerd=
{
新对象[]{新列表{“一”、“二”、“三”},3},
新对象[]{新列表{“一”,“二”},二}
};
[TestCase,TestCaseSource(“\u nunitiswerd”)]
public void计数更正(列表条目,int expectedCount)
{
Assert.AreEqual(expectedCount、Calculations.CountThis(条目));
}
计数更正(3个测试),失败:一个或多个子测试有错误 CountsRecorrect(),已忽略:未提供任何参数 计数器更正(System.Collections.Generic.List
1[System.String],2),成功
计数器更正(System.Collections.Generic.List
1[System.String],3),成功

所以第一个测试被忽略了,因为没有参数,但是我不想运行这个测试,因为它毫无意义,并且会破坏我的测试输出。我试图忽略它,这样就可以正确设置测试输出,但当我再次运行所有测试时,它会返回


有什么我遗漏了,我到处都找过了

TestCase
TestCaseSource
做两件不同的事情。您只需要删除
TestCase
属性

[TestCaseSource("_nunitIsWeird")]
public void TheCountsAreCorrect(List<string> entries, int expectedCount)
{
    Assert.AreEqual(expectedCount,Calculations.countThese(entries));
}

感谢forsvarir,这是我对文本的误读,这意味着我使用的是TastCase而不是Test。非常感谢。
[Test, TestCaseSource("_nunitIsWeird")]
public void TheCountsAreCorrect(List<string> entries, int expectedCount)