Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the Microsoft unit-testing alternative to the InlineData or TestCase attributes?

Unit test frameworks other than Microsoft have options to add input parameters and expected results using attributes.

For example,

NUnit has

[TestCase(12,4,3)]

and xUnit has

[InlineData(5, 1, 3, 9)]

What's the Microsoft way to accomplish this?

like image 697
MeanGreen Avatar asked Dec 24 '22 13:12

MeanGreen


1 Answers

You need to add Nuget packages MSTest.TestFramework and MSTest.TestAdapter (for discovery of tests) and remove the reference of Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll which is added by default. You are good to go to add input parameters:

[TestMethod]
[DataRow(10)]
[DataRow(20)]
[DataRow(30)]
public void TestMethod1(int inputValue)
{
    Assert.AreEqual(10, inputValue);
}
like image 105
Shah Avatar answered Dec 28 '22 23:12

Shah