Visual Studio参数化单元测试就像java一样

问题描述:

在java测试环境中我可以使用参数化单元测试,如下面的代码,

in java test environment I can use parameterized unit test like following code,

@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单元测试中这样做项目。我找不到参数化属性或这样的任何样本。

But how can I do this in visual studio unit test project. I cannot find parameterized attribute or any sample like this.

使用 NUnit框架,你可以将参数传递给这样的测试:

Using the NUnit framework, you would pass parameters to a test like this:

[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

This will run the two separate times, passing in the values 1, 2, 3 in the first run, and 10, 20, 30 in the second.

编辑:有关NUnit的可用测试运行器的概述,看到这个问题

For an overview of available test runners for NUnit, see this SO question