When a @BeforeTest method fails, why is it not being listed in the testng-failed.xml?

30 views
Skip to first unread message

Karthik Sankaran

unread,
Jul 8, 2021, 12:17:49 AM7/8/21
to testng-users
Stack Overflow link - https://stackoverflow.com/questions/68292525/when-a-beforetest-method-fails-why-is-it-not-being-listed-in-the-testng-failed

Apologies for improper code formatting below, couldn't find a way to format it. Please refer above link for proper formatting.

I am using maven with testng 6.14.3.

Here is my code structure:

testng.xml

````

<?xml version="1.0" encoding="UTF-8"?> <suite name="set-3" parallel="tests" thread-count="10"> <listeners> <listener class-name="org.uncommons.reportng.HTMLReporter" /> </listeners> <test name="Customer Tests"> <groups> <run> <include name="abc"/> </run> </groups> <classes> <class name="apps.Test1_BeforeTest_Of_Test2"></class> <class name="apps.Test2"></class> </classes> </test> </suite>
````

Test1_BeforeTest_Of_Test2.java

public class Test1_BeforeTest_Of_Test2{ @BeforeTest(groups = {"abc"}) public void test1Method() throws Exception { } @AfterTest(groups={"abc"}) public void test1AfterMethod() throws Exception { } }

Test2.java

public class Test2{ @Test(groups = {"abc"}) public void test2Method(){ } }

During my run, Test1_BeforeTest_Of_Test2 class fails. So, Test2 is marked as skipped. But, when I look at the testng-failed.xml that is generated at the end of the run, the failed @BeforeTest class (Test1_BeforeTest_Of_Test2) is not included/listed:

testng-failed.xml

<?xml version="1.0" encoding="UTF-8"?> <suite thread-count="10" name="Failed suite [set-3]" parallel="tests"> <listeners> <listener class-name="org.uncommons.reportng.HTMLReporter"/> </listeners> <test name="Customer Tests(failed)"> <groups> <run> <include name="abc"/> </run> </groups> <classes> <class name="apps.Test2"> <methods> <include name="test2Method"/> </methods> </class> </classes> </test> </suite>

Is this expected behaviour? Or a bug/gap in testng-failed.xml?

Ideally, when we re-run the failed tests, we expect the @BeforeTest to run as well, because it is pre-req for Test 2.

⇜Krishnan Mahadevan⇝

unread,
Jul 8, 2021, 1:09:00 AM7/8/21
to testng-users
Karthik,

This looks like a bug to me in TestNG. I did a quick check and confirm that we are missing out on configuration methods when the config method that caused the test skip resides in a different class.

I took the liberty of logging a defect on your behalf. We will get this fixed in the upcoming version of TestNG (7.5.0)

I have replied to your stackoverflow post as well.

here's the github issue link https://github.com/cbeust/testng/issues/2611

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 Scribblings @ https://rationaleemotions.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/c06dcca8-5583-4744-90db-accda8b2a4dbn%40googlegroups.com.

Karthik Sankaran

unread,
Jul 8, 2021, 8:24:23 AM7/8/21
to testng-users
Thanks Krishnan.
Reply all
Reply to author
Forward
0 new messages