How to get Maven to output JUnit5 testReporter.publishEntry() values to console?

Viewed 69

How do I get Maven to output testReporter.publishEntry() values to the command line console ?

Example

import org.junit.jupiter.api.*;
import java.util.HashMap;
import java.util.Map;

class TestReporterTest {
    @Test
    void testReportSingleValue(TestReporter testReporter) {
        testReporter.publishEntry("Single value");
    }

    @Test
    void testReportKeyValuePair(TestReporter testReporter) {
        testReporter.publishEntry("Key", "Value");
    }

    @Test
    void testReportMultipleKeyValuePairs(TestReporter testReporter) {
        Map<String, String> values = new HashMap<>();
        values.put("user", "John");
        values.put("password", "secret");

        testReporter.publishEntry(values);
    }
}

Result

(Of running C:\home\programs\apache\maven\apache-maven-3.8.4\bin\mvn.cmd install -Dtest=TestReporterTest)

Expected (something like):

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.manning.junitbook.ch02.dependencyinjection.TestReporterTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.075 s - in com.manning.junitbook.ch02.dependencyinjection.TestReporterTest
[INFO]
[INFO] timestamp = 2021-12-24T12:00:00.001, Key = Value
[INFO] timestamp = 2021-12-24T12:00:00.001, password = secret, user = John
[INFO] timestamp = 2021-12-24T12:00:00.001, value = Single value
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

Actual:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.manning.junitbook.ch02.dependencyinjection.TestReporterTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.075 s - in com.manning.junitbook.ch02.dependencyinjection.TestReporterTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

Additional information

POM file:

https://github.com/ctudose/junit-in-action-third-edition/blob/master/ch02-core/pom.xml

Full source code (TestReporterTest.java):

https://github.com/ctudose/junit-in-action-third-edition/blob/master/ch02-core/src/test/java/com/manning/junitbook/ch02/dependencyinjection/TestReporterTest.java

Full actual output (Maven command line):

PS C:\home\code\junit-in-action-third-edition-master\ch02-core> C:\home\programs\apache\maven\apache-maven-3.8.4\bin\mvn.cmd install -Dtest=TestReporterTest
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.manning.junitbook:ch02-core >-------------------
[INFO] Building ch02-core 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch02-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\home\code\junit-in-action-third-edition-master\ch02-core\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch02-core ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch02-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch02-core ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ch02-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.manning.junitbook.ch02.dependencyinjection.TestReporterTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.075 s - in com.manning.junitbook.ch02.dependencyinjection.TestReporterTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ch02-core ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ ch02-core ---
[INFO] Installing C:\home\code\junit-in-action-third-edition-master\ch02-core\target\ch02-core-1.0-SNAPSHOT.jar to C:\Users\bbsop\.m2\repository\com\manning\junitbook\ch02-core\1.0-SNAPSHOT\ch02-core-1.0-SNAPSHOT.jar
[INFO] Installing C:\home\code\junit-in-action-third-edition-master\ch02-core\pom.xml to C:\Users\bbsop\.m2\repository\com\manning\junitbook\ch02-core\1.0-SNAPSHOT\ch02-core-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.562 s
[INFO] Finished at: 2021-12-24T18:00:59+11:00
[INFO] ------------------------------------------------------------------------
PS C:\home\code\junit-in-action-third-edition-master\ch02-core>
0 Answers
Related