Package org.testng

Class Reporter


  • public class Reporter
    extends java.lang.Object
    This class is used for test methods to log messages that will be included in the HTML reports generated by TestNG.

    Implementation details.

    The reporter keeps a combined output of strings (in m_output) and also a record of which method output which line. In order to do this, callers specify what the current method is with setCurrentTestResult() and the Reporter maintains a mapping of each test result with a list of integers. These integers are indices in the combined output (avoids duplicating the output). Created on Nov 2, 2005
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.ThreadLocal<ITestResult> m_currentTestResult  
      private static boolean m_escapeHtml  
      private static java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> m_methodOutputMap
      The key is the hashCode of the ITestResult
      private static java.lang.ThreadLocal<java.util.List<java.lang.String>> m_orphanedOutput  
      private static java.util.List<java.lang.String> m_output
      All output logged in a sequential order.
    • Constructor Summary

      Constructors 
      Constructor Description
      Reporter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Erase the content of all the output generated so far.
      static ITestResult getCurrentTestResult()  
      static boolean getEscapeHtml()  
      static java.util.List<java.lang.String> getOutput()  
      static java.util.List<java.lang.String> getOutput​(ITestResult tr)  
      static void log​(java.lang.String s)
      Log the passed string to the HTML reports
      static void log​(java.lang.String s, boolean logToStandardOut)
      Log the passed string to the HTML reports.
      static void log​(java.lang.String s, int level)
      Log the passed string to the HTML reports if the current verbosity is equal or greater than the one passed in parameter
      static void log​(java.lang.String s, int level, boolean logToStandardOut)
      Log the passed string to the HTML reports if the current verbosity is equal or greater than the one passed in parameter.
      private static void log​(java.lang.String s, ITestResult m)  
      static void setCurrentTestResult​(ITestResult m)  
      static void setEscapeHtml​(boolean escapeHtml)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_currentTestResult

        private static java.lang.ThreadLocal<ITestResult> m_currentTestResult
      • m_output

        private static java.util.List<java.lang.String> m_output
        All output logged in a sequential order.
      • m_methodOutputMap

        private static java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> m_methodOutputMap
        The key is the hashCode of the ITestResult
      • m_escapeHtml

        private static boolean m_escapeHtml
      • m_orphanedOutput

        private static java.lang.ThreadLocal<java.util.List<java.lang.String>> m_orphanedOutput
    • Constructor Detail

      • Reporter

        public Reporter()
    • Method Detail

      • setCurrentTestResult

        public static void setCurrentTestResult​(ITestResult m)
      • getOutput

        public static java.util.List<java.lang.String> getOutput()
      • clear

        public static void clear()
        Erase the content of all the output generated so far.
      • getEscapeHtml

        public static boolean getEscapeHtml()
        Returns:
        If true, use HTML entities for special HTML characters (<, >, &, ...).
      • setEscapeHtml

        public static void setEscapeHtml​(boolean escapeHtml)
        Parameters:
        escapeHtml - If true, use HTML entities for special HTML characters (<, >, &, ...).
      • log

        private static void log​(java.lang.String s,
                                ITestResult m)
      • log

        public static void log​(java.lang.String s)
        Log the passed string to the HTML reports
        Parameters:
        s - The message to log
      • log

        public static void log​(java.lang.String s,
                               int level,
                               boolean logToStandardOut)
        Log the passed string to the HTML reports if the current verbosity is equal or greater than the one passed in parameter. If logToStandardOut is true, the string will also be printed on standard out.
        Parameters:
        s - The message to log
        level - The verbosity of this message
        logToStandardOut - Whether to print this string on standard out too
      • log

        public static void log​(java.lang.String s,
                               boolean logToStandardOut)
        Log the passed string to the HTML reports. If logToStandardOut is true, the string will also be printed on standard out.
        Parameters:
        s - The message to log
        logToStandardOut - Whether to print this string on standard out too
      • log

        public static void log​(java.lang.String s,
                               int level)
        Log the passed string to the HTML reports if the current verbosity is equal or greater than the one passed in parameter
        Parameters:
        s - The message to log
        level - The verbosity of this message
      • getCurrentTestResult

        public static ITestResult getCurrentTestResult()
        Returns:
        the current test result.
      • getOutput

        public static java.util.List<java.lang.String> getOutput​(ITestResult tr)