C# Nunit使用TestCaseSource运行TestCase,第一次迭代没有参数?为什么?
嗨,我是Nunit的新手,我正在将一系列对象作为TestCaseSource传递给TestCase。出于某种原因,Nunit似乎在没有向其传递任何参数的情况下首先运行测试,这会导致忽略输出: 测试: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&
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.List1[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)