Reputation: 137584
In Nunit one can reuse a test method for multiple cases.
[TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q)
{
Assert.AreEqual( q, n / d );
}
How can I do this in Visual Studio's test framework?
Upvotes: 13
Views: 6285
Reputation: 66
But of course, one can use the DataRow
attribute as shown here:
[TestClass]
public class AdditionTests
{
[DataTestMethod]
[DataRow(1, 1, 2)]
[DataRow(2, 2, 4)]
[DataRow(3, 3, 6)]
public void AddTests(int x, int y, int expected)
{
Assert.AreEqual(expected, x + y);
}
}
Upvotes: 2
Reputation: 107267
Unfortunately, MS Test doesn't support RowTests. However, a workaround can be hacked using the DataSource attribute. There is an example here.
Upvotes: 3