Skip to content

rife2/bld-junit-reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JUnit Reporter Extension for bld

License Java bld Release Snapshot GitHub CI

To install the latest version, add the following to the lib/bld/bld-wrapper.properties file:

bld.extension-reporter=com.uwyn.rife2:bld-junit-reporter

For more information, please refer to the extensions documentation.

JUnit Failure Reports

To display JUnit failure reports, add the following to your build file:

@BuildCommand(summary = "Runs the JUnit reporter")
public void reporter() throws Exception {
    new JUnitReporterOperation()
            .fromProject(this)
            .failOnSummary(true)
            .execute();
}

@Override
public void test() throws Exception {
    var op = testOperation().fromProject(this);
    // Set the reports directory
    op.testToolOptions().reportsDir(new File("build/test-results/test/"));
    op.execute();
}

Please check the JUnitReporter documentation for all available configuration options.

Failures Summary

To display a summary of all failures after running the tests, run the following:

./bld compile test
./bld reporter

The summary will look something like:

--------------------------------------------------
JUnit Failures Summary
--------------------------------------------------

[1] com.example.ExampleTests (3 failures, 0.011s)
  - [1.1] verifyFail(String)[1] ([1] foo)
  - [1.2] verifyFail(String)[2] ([2] bar)
  - [1.3] verifyHelloFoo()
[2] com.example.MoreTests (2 failures, 0.001s)
  - [2.1] verifyMore(String)[3] ([3] qux)
  - [2.2] verifyMore(String)[4] ([4] quux)

Test Group Failures

To display details about the failures in the first test group, use the group index:

./bld reporter --index=1

The output will look something like:

--------------------------------------------------
[1] com.example.ExampleTests
--------------------------------------------------

[1.1] Test: verifyFail(String)[1]
    - Name: [1] foo
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <foo> but was: <Hello World!>
    - Time: 0.009s

[1.2] Test: verifyFail(String)[2]
    - Name: [2] bar
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <bar> but was: <Hello World!>
    - Time: 0.001s

Failure Detail

To display details about the second failure in the first test group, use the group and failure indices:

./bld reporter --i=1.2

The output will look something like:

--------------------------------------------------
[1] com.example.ExampleTests
--------------------------------------------------

[1.2] Test: verifyFail(String)[2]
    - Name: [2] bar
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <bar> but was: <Hello World!>
    - Time: 0.001s
    - Trace:
        org.opentest4j.AssertionFailedError: expected: <bar> but was: <Hello World!>
                at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
                at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
                at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
                at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
                at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
                at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
                ...

All Failures

To display all failures, use the --all option:

./bld reporter --all
--------------------------------------------------                                                                                                                                  
[1] com.example.ExampleTests
--------------------------------------------------

[1.1] Test: verifyFail(String)[1]
    - Name: [1] foo
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <foo> but was: <Hello World!>
    - Time: 0.008s

[1.2] Test: verifyFail(String)[2]
    - Name: [2] bar
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <bar> but was: <Hello World!>
    - Time: 0.001s

[1.3] Test: verifyHelloFoo()
    - Name: verifyHelloFoo()
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <Hello Foo!> but was: <Hello World!>
    - Time: 0.001s

--------------------------------------------------
[2] com.example.MoreTests
--------------------------------------------------

[2.1] Test: verifyMore(String)[3]
    - Name: [3] qux
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <true> but was: <false>
    - Time: 0.0s

[2.2] Test: verifyMore(String)[4]
    - Name: [4] quux
    - Type: org.opentest4j.AssertionFailedError
    - Message:
        expected: <true> but was: <false>
    - Time: 0.0s