how to run dependent test case while rerunning failed using retryanalyzer

731 views
Skip to first unread message

Ravi Dunna

unread,
Nov 22, 2016, 10:44:31 AM11/22/16
to testng-users

I have two test cases as test case 1 and test case 2

test case 2 depends upon test case 1

I am using retry analyzer as if test case 2 fails then it will be rerun but I need test case 1 also be invoked before test case 2 reruns

⇜Krishnan Mahadevan⇝

unread,
Nov 22, 2016, 11:15:35 PM11/22/16
to testng...@googlegroups.com
Ravi,

Based on my understanding, I am elaborating your question with an example. [ If this is not what you were asking, I would request you to please help elaborate your question ]

public class TestClass {
@Test
public void independent() {
System.out.println("Hello World")
}
@Test(dependsOnMethods = "independent", retryAnalyzer = IRetryFailures.class)
public void dependent() {
//some logic goes here which is flaky enough to trigger failures
}
}


Your expectation is that, when the method dependent() has a failure and it is being retried by the retryAnalyser, you expect that independent() should also be invoked.

Explanation :

That is not how TestNG works.

When you mentioned that dependent() has a dependency on the method independent() then you have in a way established a pre-requisite for the method dependent() to be executed i.e., you have instructed TestNG : "Dear TestNG, please execute the method dependent() if and only if the method independent() passes".

Now the fact that the method dependent() was executed and it failed (for whatever reasons) and your retry analyser is being invoked emphasises that TestNG fulfilled your pre-requisite already. So why would it need to keep trying to fulfil the same pre-requisite every time the method dependent() is being retried by the retry analyser ? 

The retry analyser is expected to only attempt at retrying to current failed test method and not attempt at traversing up the hierarchy and try and fulfil every pre-requisite once again.

Please let me know if that explanation makes sense.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Sameer Jethvani

unread,
Jun 19, 2018, 9:32:44 AM6/19/18
to testng-users
Exactly retryAnalyzer won't run preRequisites . In this case I would suggest to use testng's builtin feature (which is testng-failed.xml) file . Testng generates testng-failed.xml file after whole suite/tests are executed  , which you can directly execute . It will honor all kinda prerequisites/dependencies . The only different thing here is your failing tests won't get executed right after they fail , instead they will be executed once your whole suite gets excuted.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages