MeanGreen
MeanGreen

Reputation: 3315

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?

Upvotes: 7

Views: 2868

Answers (1)

Shah
Shah

Reputation: 1399

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);
}

Upvotes: 18

Related Questions