Class TextReport

  • All Implemented Interfaces:
    AggregatedEventListener

    public class TextReport
    extends java.lang.Object
    implements AggregatedEventListener
    A listener that will subscribe to test execution and dump informational info about the progress to the console or a text file.
    • Field Detail

      • FAILURE_MARKER

        private static final java.lang.String FAILURE_MARKER
        Failure marker string.
        See Also:
        Constant Field Values
      • DEFAULT_MAX_LINE_WIDTH

        private static final int DEFAULT_MAX_LINE_WIDTH
        Default 16kb for maximum line width buffer. Otherwise we may get OOMs buffering each line.
        See Also:
        Constant Field Values
      • UNICODE_ENCODINGS

        private static java.util.Set<java.lang.String> UNICODE_ENCODINGS
        Code pages which are capable of displaying all unicode glyphs.
      • statusNames

        private static java.util.EnumMap<TestStatus,​java.lang.String> statusNames
        Status names column.
      • showEmptySuites

        private boolean showEmptySuites
        See Also:
        #showEmptySuites(boolean)
      • displayStatus

        private final java.util.EnumMap<TestStatus,​java.lang.Boolean> displayStatus
        Status display info.
      • output

        private java.io.Writer output
        A Writer for writing output messages.
      • maxClassNameColumns

        private int maxClassNameColumns
        Maximum number of columns for class name.
      • useSimpleNames

        private boolean useSimpleNames
        Use simple names for suite names.
      • timestamps

        private boolean timestamps
        Display timestamps and durations for tests/ suites.
      • outputFile

        private java.io.File outputFile
        output file name.
      • append

        private boolean append
        Append to outputFile if specified.
      • forkedJvmCount

        private int forkedJvmCount
        Forked concurrent JVM count.
      • jvmIdFormat

        private java.lang.String jvmIdFormat
        Format line for JVM ID string.
      • outWriter

        private PrefixedWriter outWriter
        Standard output, prefixed and decoded.
      • errWriter

        private PrefixedWriter errWriter
        Standard error, prefixed and decoded.
      • showNumFailuresAtEnd

        private int showNumFailuresAtEnd
        Summarize the first N failures at the end.
      • failedTests

        private java.util.List<org.junit.runner.Description> failedTests
        A list of failed tests, if to be displayed at the end.
      • stackFilters

        private java.util.List<StackTraceFilter> stackFilters
        Stack trace filters.
      • totalSuites

        private int totalSuites
      • totalErrors

        private java.util.concurrent.atomic.AtomicInteger totalErrors
      • suitesCompleted

        private java.util.concurrent.atomic.AtomicInteger suitesCompleted
      • seed

        private java.lang.String seed
    • Constructor Detail

      • TextReport

        public TextReport()
    • Method Detail

      • setShowStatusError

        public void setShowStatusError​(boolean showStatus)
      • setShowStatusFailure

        public void setShowStatusFailure​(boolean showStatus)
      • setShowStatusOk

        public void setShowStatusOk​(boolean showStatus)
      • setShowStatusIgnored

        public void setShowStatusIgnored​(boolean showStatus)
      • setMaxClassNameColumns

        public void setMaxClassNameColumns​(int maxClassNameColumns)
        Set maximum number of class name columns before truncated with ellipsis.
      • setUseSimpleNames

        public void setUseSimpleNames​(boolean useSimpleNames)
        Use simple class names for suite naming.
      • setTimestamps

        public void setTimestamps​(boolean timestamps)
        Show duration timestamps for tests and suites.
      • addConfigured

        public void addConfigured​(StackTraceFilter sfilter)
        Filter stack traces from certain frames.
      • setShowThrowable

        public void setShowThrowable​(boolean showThrowable)
        If enabled, displays extended error information for tests that failed (exception class, message, stack trace, standard streams).
        See Also:
        setShowStackTraces(boolean)
      • setShowStackTraces

        public void setShowStackTraces​(boolean showStackTraces)
        Show stack trace information.
      • setShowOutput

        public void setShowOutput​(java.lang.String mode)
        Display mode for output streams.
      • setShowNumFailures

        public void setShowNumFailures​(int num)
        Summarize N failures at the end of the report.
      • setShowEmptySuites

        public void setShowEmptySuites​(boolean showEmptySuites)
        Display suites without any errors and with no tests (resulting from filtering expressions, for example).
      • setShowSuiteSummary

        public void setShowSuiteSummary​(boolean showSuiteSummary)
        If enabled, shows suite summaries in "maven-like" format of:
         Running SuiteName
         [...suite tests if enabled...]
         Tests: xx, Failures: xx, Errors: xx, Skipped: xx, Time: xx sec [<<< FAILURES!]
         
      • setFile

        public void setFile​(java.io.File outputFile)
                     throws java.io.IOException
        Set an external file to write to. That file will always be in UTF-8.
        Throws:
        java.io.IOException
      • setAppend

        public void setAppend​(boolean append)
        Append if setFile(File) is also specified.
      • onStart

        public void onStart​(AggregatedStartEvent e)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • onChildBootstrap

        public void onChildBootstrap​(ChildBootstrap e)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • onHeartbeat

        public void onHeartbeat​(HeartBeatEvent e)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • onQuit

        public void onQuit​(AggregatedQuitEvent e)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • onOutput

        public void onOutput​(PartialOutputEvent e)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • onJvmOutput

        public void onJvmOutput​(JvmOutputEvent e)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • onTestResult

        public void onTestResult​(AggregatedTestResultEvent e)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • onSuiteResult

        public void onSuiteResult​(AggregatedSuiteResultEvent e)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • emitBufferedEvents

        private void emitBufferedEvents​(AggregatedSuiteResultEvent e)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • flushOutput

        private void flushOutput()
                          throws java.io.IOException
        Flush output streams.
        Throws:
        java.io.IOException
      • emitSuiteStart

        private void emitSuiteStart​(org.junit.runner.Description description,
                                    long startTimestamp)
                             throws java.io.IOException
        Suite prologue.
        Throws:
        java.io.IOException
      • emitSuiteEnd

        private void emitSuiteEnd​(AggregatedSuiteResultEvent e,
                                  int suitesCompleted)
                           throws java.io.IOException
        Suite end.
        Throws:
        java.io.IOException
      • emitStatusLine

        private void emitStatusLine​(AggregatedResultEvent result,
                                    TestStatus status,
                                    long timeMillis)
                             throws java.io.IOException
        Emit status line for an aggregated event.
        Throws:
        java.io.IOException
      • logShort

        private void logShort​(java.lang.CharSequence message,
                              boolean trim)
                       throws java.io.IOException
        Log a message line to the output.
        Throws:
        java.io.IOException
      • logShort

        private void logShort​(java.lang.CharSequence message)
                       throws java.io.IOException
        logShort, trim whitespace.
        Throws:
        java.io.IOException
      • isPassthrough

        private boolean isPassthrough()
        Returns:
        true if we can emit output directly and immediately.
      • shortTimestamp

        private java.lang.String shortTimestamp​(long ts)
        Format a short timestamp.