Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio parameterized unit test like java

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.

like image 532
bayramucuncu Avatar asked Jul 26 '12 11:07

bayramucuncu


1 Answers

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
}

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.

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

like image 102
Kjartan Avatar answered Sep 27 '22 02:09

Kjartan