NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times.
[RowTest]
[Row(1001,1,2,3)]
[Row(1,1001,2,3)]
[Row(1,2,1001,3)]
public void SumTests(int x, int y, int z, int expected)
{
...
}
What's the best way to accomplish this same type of thing using MSTest? I can't find a similar set of attributes.
You can create a base class with the test method and the parameters as virtual properties. When you inherit from this class you only need to override the properties with the desired values. Please see the sample code:
For those using MSTest2, DataRow + DataTestMethod is available to do exactly this:
More about it here
You can have this capability by writing a small extension of mstest as shown here.
http://blogs.msdn.com/b/vstsqualitytools/archive/2009/09/04/extending-the-visual-studio-unit-test-type-part-2.aspx
My answer is similuar to @oscar-e-fraxedas-tormo one.
You can subclass from one of the generated classes that have from 1 to 100 test methods inside and provide all test logic in the derived class. In the example below:
The class
Ha_ha_ha_Test
will contain42
generated rows (methods). For each of this row, the custom methodGetNextDataRow
will be called in order to provide required test data.More details:
https://github.com/dzhariy/mstest-rows
Actually, the Parameterized Unit Test (PUT) is a natural generalization of unit test. And Microsoft Research has a project called Pex that will generate the PUT for your Class Under Test (CUT) automatically. Pex is an auto test input generation tool. Instead of preparing the test data yourself, the Pex tool will find the inputs of interest for the parameters of CUT and generate the unit test cases accordingly. Please check here.
Would this help?