I have the following method which generates a set of test cases!
public IEnumerable PrepareTestCases(param1)
{
foreach (string e
If you look at TestCaseSourceAttribute doc you will see there is no any way to pass the parameter to the method which returns test cases.
The method, which generates test cases, should be parameterless.
So, assuming you are going to avoid code duplication and you need to reuse the same method to generate a few test case lists, I'd recommend you to do the following:
Write parameterized method which actually generates test cases sets:
(PrepareTestCases()
already does that)
public IEnumerable PrepareTestCases(string param)
{
foreach (string entry in entries)
{
yield return CallMyMethod(param);
}
}
Write parameterless wrappers which call test cases generator and pass desired parameter there:
public IEnumerable PrepareTestCases_Param1()
{
return PrepareTestCases("param1");
}
public IEnumerable PrepareTestCases_Param2()
{
return PrepareTestCases("param2");
}
Write test methods and pass paremeterless wrappers there as test case sources:
[TestCaseSource("PrepareTestCases_Param1")]
public void TestRun1(ResultsOfCallMyMethod data)
{
}
[TestCaseSource("PrepareTestCases_Param2")]
public void TestRun2(ResultsOfCallMyMethod data)
{
}