什么是 Microsoft 单元测试替代 InlineData 或 TestCase 属性? [英] What's the Microsoft unit-testing alternative to the InlineData or TestCase attributes?
本文介绍了什么是 Microsoft 单元测试替代 InlineData 或 TestCase 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Microsoft 以外的单元测试框架可以选择使用属性添加输入参数和预期结果.
Unit test frameworks other than Microsoft have options to add input parameters and expected results using attributes.
例如,
NUnit 有
[TestCase(12,4,3)]
和 xUnit 有
[InlineData(5, 1, 3, 9)]
Microsoft 实现此目的的方法是什么?
What's the Microsoft way to accomplish this?
推荐答案
您需要添加 Nuget 包 MSTest.TestFramework 和 MSTest.TestAdapter(用于发现测试)并删除默认添加的 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
的引用.你好去添加输入参数:
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);
}
这篇关于什么是 Microsoft 单元测试替代 InlineData 或 TestCase 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文