Class QuietTestOutputListener

java.lang.Object
com.vaadin.flow.testutil.QuietTestOutputListener
All Implemented Interfaces:
org.junit.platform.launcher.TestExecutionListener

public class QuietTestOutputListener extends Object implements org.junit.platform.launcher.TestExecutionListener
Buffers everything a test class or a test method writes to System.out and System.err and throws it away unless the test fails. Tests that intentionally trigger logging, such as the ones covering error handling, thus no longer flood the build output, while everything a failing test logged is printed as usual.

Output logged through java.util.logging is not captured, since its handlers keep writing to the stream they were created with; configure the logger levels instead when such output is too noisy.

Replacing System.out and System.err affects the whole JVM, so this only works when tests run one at a time. Surefire runs the unit tests sequentially; do not enable it for tests that run in parallel, such as the TestBench integration tests run by Failsafe, where whichever test happens to be running would capture, and on success discard, the output of the others. Should tests nevertheless start on more than one thread, the capture gives up for the rest of the run instead of mixing up their output.

Registered automatically via ServiceLoader in META-INF/services/org.junit.platform.launcher.TestExecutionListener and enabled by the "vaadin.test.quietOutput" system property, which Surefire sets for unit tests. Run with -Dvaadin.test.quietOutput=false to see the output of passing tests again.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the system property that enables the capture.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    executionFinished(org.junit.platform.launcher.TestIdentifier testIdentifier, org.junit.platform.engine.TestExecutionResult testExecutionResult)
     
    void
    executionStarted(org.junit.platform.launcher.TestIdentifier testIdentifier)
     
    void
    testPlanExecutionFinished(org.junit.platform.launcher.TestPlan testPlan)
     
    void
    testPlanExecutionStarted(org.junit.platform.launcher.TestPlan testPlan)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.platform.launcher.TestExecutionListener

    dynamicTestRegistered, executionSkipped, fileEntryPublished, reportingEntryPublished
  • Field Details

    • ENABLED_PROPERTY

      public static final String ENABLED_PROPERTY
      Name of the system property that enables the capture.
      See Also:
  • Constructor Details

    • QuietTestOutputListener

      public QuietTestOutputListener()
  • Method Details

    • testPlanExecutionStarted

      public void testPlanExecutionStarted(org.junit.platform.launcher.TestPlan testPlan)
      Specified by:
      testPlanExecutionStarted in interface org.junit.platform.launcher.TestExecutionListener
    • executionStarted

      public void executionStarted(org.junit.platform.launcher.TestIdentifier testIdentifier)
      Specified by:
      executionStarted in interface org.junit.platform.launcher.TestExecutionListener
    • executionFinished

      public void executionFinished(org.junit.platform.launcher.TestIdentifier testIdentifier, org.junit.platform.engine.TestExecutionResult testExecutionResult)
      Specified by:
      executionFinished in interface org.junit.platform.launcher.TestExecutionListener
    • testPlanExecutionFinished

      public void testPlanExecutionFinished(org.junit.platform.launcher.TestPlan testPlan)
      Specified by:
      testPlanExecutionFinished in interface org.junit.platform.launcher.TestExecutionListener