This solution I went with first created a class for my custom test case
public class CustomTestCase { public CustomTestCase(int SearchNumber, List<int> List, int Result) { searchNumber = SearchNumber; list = List; result = Result; } private int searchNumber; private List<int> list; private int result; public string TestName() { return string.Format("TestChop({0},{{{1}}})", searchNumber, String.Join(",", list)); } public TestCaseData SimpleTest() { return new TestCaseData(searchNumber, list).Returns(result).SetName(this.TestName()); } }
And then I used this to create a TestCaseSource
private static IEnumerable ReturnChopCases() { List<int> emptyList = new List<int> { }; yield return new CustomTestCase(3,emptyList,-1).SimpleTest(); List<int> singleItemList = new List<int> { 1 }; yield return new CustomTestCase(3, singleItemList, 1).SimpleTest(); yield return new CustomTestCase(3, singleItemList, 1).SimpleTest(); }
The test is the same.
I still think that NUnit should generate more useful names, but I found this the easiest way to solve my problem, and if I want to deal with exceptions, I could just create another method to handle them.
Note. Remember to enable using System.Collections; and using System.Collections.Generic; .
source share