java - TestNG dataproviders with a @BeforeClass -
i trying run class multiple tests under 2 different conditions. have bunch of tests related search. adding new functionality of new search strategy, , in meantime want run written tests under both configurations. have multiple classes each multiple tests want streamline process as possible. ideally it'd great setup in @beforeclass data provider tests in class run twice under different configurations, doesn't possible.
right have:
public class searchtest1 { @test(dataprovider = "searchtype") public void test1(searchtype searchtype) { setsearchtype(searchtype); //do test1 logic } @test(dataprovider = "searchtype") public void test2(searchtype searchtype) { setsearchtype(searchtype); //do test2 logic } @dataprovider(name = "searchtype") public object[][] createdata() { return new object[][]{ new object[] {searchtype.scheme1, searchtype.scheme2} } } }
is there better way this?
if want avoid having annotate each , every method data provider, can use factory
instead.
public class searchtest1 { private final searchtype searchtype; public searchtest1( searchtype searchtype ) { this.searchtype = searchtype; } @test public void test2() { //do test2 logic } ... }
and factory class be:
public class searchtestfactory { @factory public object [] createinstances() { return new object[] { new seartchtest1( searchtype.one ), new searchtest1( searchtype.two ) }; } }
see more on here.
then can either have 1 factory enumerates every test class or separate factory each, first 1 less flexible, second 1 means more code.
Comments
Post a Comment