tags:

views:

79

answers:

1

Hello,

I am writing a test case where in I want to run a one DataPoint for one test case and second DataPoint for second test case.

@RunWith(Theories.class)
public class DummyTest {

    @DataPoints
    public static String[] getFileNames() {
        return new String[] { "firstFile.txt","firstFile1.txt" };
    }

    @Theory
    public void test1(String fileName) throws Exception {
        System.out.println(fileName);
        assertThat(true, is(equalTo(Boolean.TRUE)));
    }

    @DataPoints
    public static String[] getSecondFileNames() {
        return new String[] { "secondFile.txt","secondFile1.txt" };
    }

    @Theory
    public void test2(String fileName) throws Exception {
        System.out.println(fileName);
        assertThat(true, is(equalTo(Boolean.TRUE)));
    }

}

I want that for first test case my first datapoints i.e. getFileNames method is called and for second test case getSecondFileNames datapoints should be called. Can anybody suggest is this feasible?

Thanks,
Shekhar

+1  A: 

Tests can be grouped into "fixtures", where a fixture is a set of code that shares the same setup. Put the tests for cases using the same datapoints together in the same class, so you have one class for each set of data.

Nathan Hughes
What I was looking for was a way to write all the test in a same class. Can we define two datapoints in one test class?
Shekhar