digitalronin
digitalronin

Reputation: 636

Junit. Is there a way to get output formatted like rspec output?

I usually code in ruby, and use rspec for my unit tests.

Now I have to do some work in java, so I'm using JUnit. The output from multiple test suites looks like this;

test:
    [junit] Running com.whatever.MapperTest
    [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.542 sec
    [junit] Running com.whatever.ReducerTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.391 sec
    [junit] Running com.whatever.DenormalizerTest
    [junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.046 sec
    [junit] Running com.whatever.EventTest
    [junit] Tests run: 31, Failures: 0, Errors: 0, Time elapsed: 0.081 sec

BUILD SUCCESSFUL
Total time: 5 seconds

That's quite dense text, and makes it a bit difficult to see failures and errors.

With RSpec, I get output like this;

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

Where '.' represents a passing test, 'F' is a failure and 'E' is an error. Below this output is detail of all the failures/errors.

I find that format a lot easier to look at - failures and errors leap out in a way that they don't when looking at the counts of run/fails/errors in the normal summary output from JUnit.

I have been through a couple of options in the junit task of the build.xml file, including;

<formatter type="plain" usefile="false" />

and

<junit printsummary="true">

Using formatter="plain" fills the screen with too much redundant information. I don't need to see every single pass listed out as a line of text - just a single dot is ideal.

Does anyone know if a custom formatter has been written that produces something similar to the format I want?

Whatever tool I use needs to work on the command line, so fancy GUI tools aren't an option.

Upvotes: 2

Views: 1366

Answers (1)

Joe
Joe

Reputation: 3059

You can write your own formatter to solve the problem.

Here are some good instructions to get you started: http://shaman-sir.wikidot.com/one-liner-output-formatter

Basically, you'll want to change addError to keep a record of tests with errors also. Then change endTest() to output a . instead of all the information there unless the test is in the failure or error Set.

The API for ANT is included with the binary distribution of it. Remember to update the junit formatter classname with the newly created formatter.

Upvotes: 1

Related Questions