Search code examples
javaunit-testinggradlejunitjunit5

Add Junit Pioneer @Issue annotation info to Gradle Test Report


I put @Issue annotation from JUnit Pioneer library on my test suites. Look at the code snippet below:

@Test
@Issue("TY-5232")
void shouldReturn200IfTryingToCreateNewAccountWithAvailableName() {...}

Also, I'm using Gradle Test Report to produce HTML report of tests' results. I wonder is to possible to add information about issue to the Gradle test report? I'd like to see which test belongs to particular task.

Perhaps I need to register some callback but I didn't find specific way to do it. Any ideas?


Solution

  • I manage to solve the problem differently.

    First, I create custom IssueProccessor that implements the corresponding interface in JUnit Pioneer library.

    public class SimpleIssueProcessor implements IssueProcessor {
    
        @Override
        public void processTestResults(List<IssueTestSuite> issueTestSuites) { 
            /* this callback receives information about all tests marked with `@Issue` annotation */ 
        }
    
    }
    

    Then I register it as Java ServiceLoader so JUnit uses the instance of the class during its lifecycle. In order to do that, I create a file src/test/resources/META-INF/services/org.junitpioneer.jupiter.IssueProcessor with the content below:

    com.my.company.SimpleIssueProcessor
    

    This is the fully qualified name of the SimpleIssueProcessor implementation.

    And finally, I create another file src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener with content:

    org.junitpioneer.jupiter.issue.IssueExtensionExecutionListener
    

    That's the JUnit TestExecutionListener provided by JUnit Pioneer library that delegates information to IssueProcessor implementation.


    And that's basically it. Now you process the information in SimpleIssueProcessor callback and build any documentation you want.