Visual studio parameterized unit test like java

Viewed 7875

In a Java test environment I can use parameterized unit tests as in the 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);
    }
}

How can I do this in a Visual Studio unit test project? I can`t find any parameterized attribute or any sample like this.

3 Answers

This is now also possible via the MSTest 2 framework.

It comes with a 'DataTestMethod' attribute and related 'DataRow' attributes. Which makes it similar in how NUnit works.

Here are some good examples on how to use it.

Related