Andrea Giuliano
Andrea Giuliano

Reputation: 378

TestNG/Junit configure output style in console

When I write and execute test, I feel very distracting to see a lot of noise that TestNG writes on the terminal like this:

[testng] ===============================================
[testng]     Mynamespace.Test
[testng]     Tests run: 4, Failures: 0, Skips: 0
[testng] ===============================================
[testng]
[testng] THIS:Foo(super=Foo(param=ABC1234567, name=null, param=null), id=-314151617)
[testng] PASSED: testAVeryCoolThing on testConstructor(mynamespace.SomeTest)
lines and lines like this...

I was used (not with junit/testng) to have test output like this:

.......F....E.................................
..............................................
..............................................

So basically for every test passing, write a simple dot (it's passing, I'm happy) and for failures and errors the equivalent letter and then later show me only the output from failing tests. Is this something achievable with TestNG/JUnit?

Upvotes: 0

Views: 138

Answers (1)

Ivan Pronin
Ivan Pronin

Reputation: 1906

Just read the docs. You need to override some methods from TestListenerAdapter: (taken from the docs):

Here is a listener that displays a "." for each passed test, a "F" for each failure and a "S" for each skip:

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

  @Override
  public void onTestFailure(ITestResult tr) {
    log("F");
  }

  @Override
  public void onTestSkipped(ITestResult tr) {
    log("S");
  }

  @Override
  public void onTestSuccess(ITestResult tr) {
    log(".");
  }

  private void log(String string) {
    System.out.print(string);
    if (++m_count % 40 == 0) {
      System.out.println("");
    }
  }

}

Upvotes: 1

Related Questions