在 Java 测试环境中,我可以使用参数化单元测试,如以下代码所示:
@RunWith(value = Parameterized.class)
public class JunitTest6 {
private int number;
public JunitTest6(int number) {
this.number = number;
}
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
return Arrays.asList(data);
}
@Test
public void pushTest() {
System.out.println("Parameterized Number is : " + number);
}
}
如何在 Visual Studio 单元测试项目中执行此操作?我找不到任何参数化属性或任何这样的示例。
使用NUnit框架 http://www.nunit.org,您可以将参数传递给这样的测试:
[TestCase(1, 2, 3)]
[TestCase(10, 20, 30)]
public void My_test_method(int first, int second, int third)
{
// Perform the test
}
这将运行两次单独的时间,并传递值1, 2, 3
在第一次运行中,并且10, 20, 30
在第二。
编辑:有关 NUnit 可用测试运行程序的概述,看到这个问题 https://stackoverflow.com/questions/336655/what-is-the-best-nunit-test-runner-out-there
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)