The version of TestNG used does not support setting config failure policy to 'continue'

278 views
Skip to first unread message

Ish Abbi

unread,
Sep 9, 2021, 8:22:25 AM9/9/21
to testng-users
Hi All,

Recently came across an issue where for a failed "@BeforeMethod" hook, the rest of the tests in my suite are getting skipped. Going through the documentation I found that we can set the configFailurePolicy as 'continue'.

But on setting that in gradle, I get the following exception :

The version of TestNG used does not support setting config failure policy to 'continue'

I'm using gradle 6.7 and really don't want to hard-code my suite in xml files. Are there any alternatives for the same? As, in can the configurations be tweaked via listeners?

Thanks in Advance,
Ish

Krishnan Mahadevan

unread,
Sep 11, 2021, 1:01:49 AM9/11/21
to testng...@googlegroups.com

Can you please share a sample project that can be used to reproduce the problem ?

 

 

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.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/99824016-018a-4d17-9564-c39f4af8317an%40googlegroups.com.

Ish Abbi

unread,
Sep 13, 2021, 2:16:38 PM9/13/21
to testng...@googlegroups.com
Hi Krishnan,

Sure, please allow me sometime to share a sample of the framework.

You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/Tck1UYdGNz0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/F053CD27-08E9-4098-BF93-3E170A51B054%40gmail.com.

Ish Abbi

unread,
Sep 13, 2021, 4:32:07 PM9/13/21
to testng...@googlegroups.com
Hi Krishnan,

PFA sample project which will help reproduce the issue. I've deliberately added one skipped exception in order to reproduce the issue.

If I add "configFailurePolicy" as "continue" while the dependency of testng is 7+, I get the below exception :
Screenshot 2021-09-14 at 1.57.48 AM.png
If I downgrade my testng dependency, I'm able to use the configFailurePolicy but I lose my ability to get the exception when my tests skip.
Also, in both cases if the "configFailurePolicy" is missing then in case of any skipped test, the rest of my tests also get skipped.

Ish Abbi

unread,
Sep 15, 2021, 2:08:11 AM9/15/21
to testng-users
I found a work around for the approach to setting the configFailurePolicy, sharing in this thread for reference.

I'm no longer using gradle options to mark the failure policy as continue but instead using the "IAlterSuiteListener" to alter the config failure policy to continue.


public class ConfigureFailurePolicyListener implements IAlterSuiteListener {
    @Override
    public void alter(List<XmlSuite> suites) {
        TestLogger.log("Number Of Suite Files Found : " + suites.size());
        for (XmlSuite suite : suites) {
            if (suite.getConfigFailurePolicy().equals(XmlSuite.FailurePolicy.SKIP)) {
                TestLogger.log("Setting the configFailurePolicy to \"continue\" for the suite : "
                        + suite.getName());
                suite.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
            }
        }
    }
}

listeners << "com.rookieintraining.ui.listeners.ConfigureFailurePolicyListener"

This allows me to set the value as continue for all the suites that are executed (which meets the current requirement).

⇜Krishnan Mahadevan⇝

unread,
Sep 17, 2021, 1:22:20 AM9/17/21
to testng-users
I took a closer look at the project.

Here's what is going wrong.
  • You are using a very old version of Gradle.
  • This version of Gradle has a TestNG integration via org.gradle.api.tasks.testing.Test#useTestNG(groovy.lang.Closure),  which attempts at invoking the setConfigFailurePolicy() method in TestNG that used to accept a String parameter.
  • We got rid of that variant and had it replaced with org.testng.xml.XmlSuite#setConfigFailurePolicy which accepts the enum FailurePolicy and not the String.
End result: You would see this error, which if you enable stack trace printing should show you the actual root cause too:
Caused by: java.lang.NoSuchMethodException: org.testng.TestNG.setConfigFailurePolicy(java.lang.String)
        at org.gradle.api.internal.tasks.testing.testng.TestNGTestFramework.verifyMethodExists(TestNGTestFramework.java:100)
        ... 85 more
You have a couple of alternatives:
  1. You resort to a programmatic way of setting the config failure policy via a TestNG listener (which is exactly what you have done)
  2. Upgrade your Gradle version to the latest version and try again. It should go off, because TestNG also uses Gradle for its builds.
  3. You dont use the useTestNG() task, but instead use a Java Exec task, wherein you invoke the TestNG main method and also set whatever needs to be set via command line parameters. [ Something like this https://groups.google.com/g/testng-users/c/CqTNqaPeAQY/m/TLbFOsY5AgAJ ]
Hope that helps!

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/


Ish Abbi

unread,
Sep 18, 2021, 2:39:25 AM9/18/21
to testng...@googlegroups.com
Thanks Krishnan for sharing the alternatives. This really helps.

Reply all
Reply to author
Forward
0 new messages