Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

@AfterSuite no longer takes dependency injection

84 views
Skip to first unread message

Greg Martz

unread,
Oct 7, 2024, 9:21:13 AM10/7/24
to testng-users
I admit I have been using an older version of testng.  I was just allowed to upgrade to the latest.  This however, has broken my AfterSuite code.  In this code, I need to get the total number of skipped and failed tests so I can communicate this with a 3rd party tool.  However, that seems to be no longer possible as it won't accept ITestConext as a parameter.  
I have looked into using OnFinish with ISuite, however that occurs after AfterSuite and has no access to the driver that I need.
How can I get the numberOfFailed and numberOfSkipped tests after all tests have completed in the suite?

Thanks!
Greg

Krishnan Mahadevan

unread,
Oct 9, 2024, 1:55:49 AM10/9/24
to testng...@googlegroups.com
Greg,

Here’s a sample that shows how you can do this

Java
import org.testng.Assert;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.Reporter;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;

public class TestCaseSample {

    @Test
    public void failingTest() {
        Assert.fail();
    }

    @Test
    public void passingTest() {}

    @AfterSuite
    public void afterSuite() {
        ISuite suite = Reporter.getCurrentTestResult().getTestContext().getSuite();
        long count = suite.getResults().values()
                .stream().map(ISuiteResult::getTestContext)
                .mapToLong(it -> it.getFailedTests().getAllResults().size())
                .sum();
        System.err.println("Number of failed tests = " + count);
    }
}

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/CAJ5e%3DehRUC7q7ST4Z2dUFkX-%3D6oEjgspX8VAhzMvgHNv2Arhuw%40mail.gmail.com.

Greg Martz

unread,
Oct 10, 2024, 1:17:07 PM10/10/24
to testng...@googlegroups.com
Perfect!  thank you so much!

Thanks!
Greg


Reply all
Reply to author
Forward
0 new messages