There is, of course, another way to do this which has not been discussed in this thread, i.e. by way of inheritance of the class containing the TestMethod. In the following example, only one TestMethod has been defined but two test cases have been made.
In Visual Studio 2012, it creates two tests in the TestExplorer:
DemoTest_A12_B4.test
public class Demo
{
int a, b;
public Demo(int _a, int _b)
{
this.a = _a;
this.b = _b;
}
public int Sum()
{
return this.a + this.b;
}
}
public abstract class DemoTestBase
{
Demo objUnderTest;
int expectedSum;
public DemoTestBase(int _a, int _b, int _expectedSum)
{
objUnderTest = new Demo(_a, _b);
this.expectedSum = _expectedSum;
}
[TestMethod]
public void test()
{
Assert.AreEqual(this.expectedSum, this.objUnderTest.Sum());
}
}
[TestClass]
public class DemoTest_A12_B4 : DemoTestBase
{
public DemoTest_A12_B4() : base(12, 4, 16) { }
}
public abstract class DemoTest_B10_Base : DemoTestBase
{
public DemoTest_B10_Base(int _a) : base(_a, 10, _a + 10) { }
}
[TestClass]
public class DemoTest_B10_A5 : DemoTest_B10_Base
{
public DemoTest_B10_A5() : base(5) { }
}