I would like to run programmatically an instance of TestNG test.
My test is like this:
public class MyTest {
private Browser browser;
private User user;
public MyTest(Browser browser, User user) {
this.browser = browser;
this.user = user;
}
@Test public void testExample() {
...
}
}
Since my test requires some objects to be passed to it’s constructor to work I can’t simply provide the test class object. So this won’t work:
TestNG testng = new TestNG();
testng.setTestClasses(MyTest.class);
testng.run();
Any ideas on how can I do it with TestNG?
You can use a stactic variable or method to get those objects. But that only works if you dont plan on parallel execution of your tests.
ExampleClass could be createdin another test class in an @BeforeSuite or @BeforeTest method.