What changes do i need to make to the following please?
I’d like make sure that testInsert method to only run when testInternalAccess passes and testInternalAccess not count as a failure.
@Test
public void testInternalAccess() {
URL url = null;
try {
url = new URL("http://internalpage");
InputStream is = url.openConnection().getInputStream();
} catch (Exception e) {
fail();
}
}
@Test(groups = "database", dependsOnMethods = "testInternalAccess")
public void testInsert() {
// some code
}
In the above example:
testInternalAccessruns, fails and being reported as a failed testtestInsertruns and fails
Or, using creator’s of TestNG example
@Test
public serverStartedOk() {}
@Test(dependsOnMethods = { "serverStartedOk" })
public method1() {}
How will method1 know whether server actually started ok? How will serverstartedOk communicate to the world it’s state?
Based on the discussion we had above, following is the brief summary.
As you wish to run the method
testinternalAcecessbefore you run all the tests in the class use@BeforeClassThe method runs only once and before all tests run in the suite! And you test method would be some thing as below
Bingo and this would work!