Illia
Illia

Reputation: 51

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();
}

Upvotes: 0

Views: 2357

Answers (2)

bangoria anjali
bangoria anjali

Reputation: 400

See in your code,

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

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

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

@Test(dependsOnMethods = "createSmth", alwaysRun=true)
public void deleteSmth()  {
    ///
}

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

createSmth and deleteSmth always run even if dependant method will get fail to execute. Before and after class annotation will be run before/after the first/last test method in the current class is invoked. @BeforeClass when multiple tests need to share the same computationally expensive setup code. @BeforeClass will be executed only once.

It works even if you will run using testng.xml in parellel

Upvotes: 1

Illia
Illia

Reputation: 51

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/

Upvotes: 0

Related Questions