I inherited two dozen or so java tests and when the suite is ran, everything is printed whether passing or failing. I would like to only print failures/failure logs and get a total count of tests that passed. Most of the tests use a data source CSV file and iterate over the rows to verify different data values. IntelliJ prints the total number of tests ran, failures and skips. How can I print the same information so that I can see it when I run the suites via the command line?

When I log anything, it prints every time the test is ran. I only want a final count of the total number of tests that passed printed once.

Below is a sample of the code that runs.

public class metaTest
    public Iterable getData() throws IOException {
        String inPath = Path.toResource("test.csv");
@Test(groups = {"test"}, threadPoolSize = 20)
    @IterateOverReturnValue(method = "getData")
    public void processLine(CsvLine line) throws Exception {

        String URL = line.get(0);   
        AssertMulti asrt = new AssertMulti();
            page_title = page.getTitle();
            asrt.assertNotEmpty(page_title, "Could NOT parse page title");

 try {
            HtmlPage page = HtmlPage.fromUrl(URL);
            response_code = String.valueOf(page.getCode());
} catch (Exception e) {
            throw e;

        } finally {
            String error_log = asrt.getAsOneString();
            String pass_fail = error_log.isEmpty() ? "PASS" : "FAIL";

  • What build systems are you using. There are many tools in the maven ecosystem that can summarize test results -- look at the surefire documentation. – Bob Dalgleish Jan 31 '19 at 21:54
  • TestNG and Maven. I can't find one that logs the summary per test in the terminal. It generates an HTML file after the suite has run, which is fine. I am looking for a way to print the total number of tests when running via the terminal so that I can summarize each of the 24 various files individual tests. – kylokyler Jan 31 '19 at 22:49
  • It generates an XML file for each test class. There is a way to insert a different report writer into the final stages of surefire's reporting to get what you want. – Bob Dalgleish Feb 1 '19 at 14:10

One way to do this is to create a DotTestListener Class which gets callbacks with test statuses.

In this example from http://testng.org/doc/documentation-main.html#running-testng output is printed to the console but you could alter it to store different info and put it in different place.

public class DotTestListener extends TestListenerAdapter {
 private int m_count = 0;

    public void onTestFailure(ITestResult tr) {

    public void onTestSkipped(ITestResult tr) {

    public void onTestSuccess(ITestResult tr) {

    private void log(String string) {
       if (++m_count % 40 == 0) {
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.