Illia Illia - 1 month ago 11
Java Question

Marking test methods with @Test(dependsOnMethods=..) testNG annotation make them not to execute

I've got a problem in my production test suite runs.

testng.xml has set up to run test suite in multithreaded environment using custom listener. As result there are several driver instances that are running separately and in parallel, with each test.
Last time suite started failing and I noticed strange behavior:

Each test in each test method which has dependsOnMethods in its @Test annotation do not execute. Driver just skipps them, and does not execute @AfterTest methods as result.
Or, I suppose It does not skip them, it does not report to depend methods that "login" method is done and they can go on and execute.

But i have no idea why is it happening

Smth like this:

@BeforeClass
protected void beforeClassInit(){
setUp(///);
}

@Test
public void login() {
//login activities
}

@Test(dependsOnMethods = "login")
public void createSmth() {
///
}

@Test(dependsOnMethods = "createService")
public void deleteSmth() {
///
}

@AfterClass(alwaysRun = true)
protected void afterClass() {
shutDown();
}

Answer

The problem was in testng logic. Through tons of experiments it was defined, that TestNG always runs dependent methods in the end of parallel run. Means, i.e. you have 3 Test Classes: Test1.java Test2.java Test3.java

and each has some test methods.

TestNG suite contains that 3 classes will run each non-dependent method from those classes, than come back and finish run of those dependent methods which left.

Crazy behavior, but looks that's it/