我正在尝试在 NUnit 中使用 TestCaseSource
运行多个测试,其中一个参数是一个数组
private static readonly object[] ReturnChopCases =
{
new TestCaseData(3, new List<int> {}).Returns(-1),
new TestCaseData(3, new List<int> {1}).Returns(1),
new TestCaseData(1, new List<int> {1,2}).Returns(1),
};
[TestCaseSource("ReturnChopCases")]
public int test_chop(int SearchNumber, int[] SearchArray)
{
return Chopper.Chop(3, SearchArray);
}
问题是测试运行器(我使用的是 NUnit 测试适配器)中显示的名称非常无用,它们都显示为 test_chop(0,System.Int32[])
或者如果使用 List
,然后使用 test_chop(0,System.Collections.Generic.List`1[System.Int32])
。
如何保留可读性强的测试并为测试运行程序中的测试提供有用的测试名称?我已经尝试了一些方法,但我仍然得到上面提到的名字。
最佳答案
使用SetName
函数为测试命名
new TestCaseData(3, new List<int> {}).Returns(-1).SetName("test_chop_List<int>"),
关于c# - 使用数组或泛型时 TestCase 在 NUnit 中的显示名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26933741/