什么是Microsoft单元测试替代InlineData或TestCase属性?

Mea*_*een 2 c# unit-testing vs-unit-testing-framework

除Microsoft之外的单元测试框架具有使用属性添加输入参数和预期结果的选项.

例如,

NUnit有

[TestCase(12,4,3)]
Run Code Online (Sandbox Code Playgroud)

和xUnit有

[InlineData(5, 1, 3, 9)]
Run Code Online (Sandbox Code Playgroud)

微软的方法是什么?

Sha*_*hah 6

您需要添加Nuget包MSTest.TestFrameworkMSTest.TestAdapter(用于发现测试)并删除Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll默认添加的引用.你最好去添加输入参数:

[TestMethod]
[DataRow(10)]
[DataRow(20)]
[DataRow(30)]
public void TestMethod1(int inputValue)
{
    Assert.AreEqual(10, inputValue);
}
Run Code Online (Sandbox Code Playgroud)