vendredi 23 décembre 2016

Reduce JUnit Output

I am programmatically running a JUnit test with the command

The method that I use is:

String res = runProcess("java -classpath " + dirPath + ";" + classpath + " org.junit.runner.JUnitCore "+ getClassName(filePath));

private static String runProcess(String command) throws Exception {
    Process process = Runtime.getRuntime().exec(command);
    String inputStr = IOUtils.toString(process.getInputStream());
    process.waitFor();
    return inputStr;
}

However, it outputs a lot of additional information such as the number of failures, time it took to run, and junit information.

A sample out looks like this:

JUnit version 4.12
.E
Time: 0.011
There was 1 failure:
1) test10(ErrorTestLang)
java.lang.AssertionError: Contract failed: compareTo-equals on fraction1 and fraction4
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.assertTrue(Assert.java:41)
    at ErrorTestLang.test10(ErrorTestLang.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
    at org.junit.runner.JUnitCore.main(JUnitCore.java:36)

FAILURES!!!
Tests run: 1,  Failures: 1

My goal is to programmatically run the JUnit test suite multiple times as I modify it and ensure that the results are still the same. That is, all of the same assertions fail/pass even if I remove some lines of unused code.

Thus, I am interested in the part of the output that is:

java.lang.AssertionError: Contract failed: compareTo-equals on fraction1 and fraction4

Since I will be comparing that with other results and don't want to consider the details such as time it took to run or line numbers.

Is there a flag to make the JUnit output more concise?

Aucun commentaire:

Enregistrer un commentaire