Class TestResult

java.lang.Object
org.testng.internal.TestResult
All Implemented Interfaces:
Comparable<ITestResult>, IAttributes, ITestResult

public class TestResult extends Object implements ITestResult
This class represents the result of a test.
  • Field Details

    • m_method

      private ITestNGMethod m_method
    • skippedDueTo

      private List<ITestNGMethod> skippedDueTo
    • skipAnalysed

      private boolean skipAnalysed
    • m_status

      private int m_status
    • m_throwable

      private Throwable m_throwable
    • m_startMillis

      private long m_startMillis
    • m_endMillis

      private long m_endMillis
    • m_name

      private String m_name
    • m_host

      private String m_host
    • m_parameters

      private Object[] m_parameters
    • m_instanceName

      private String m_instanceName
    • m_context

      private ITestContext m_context
    • parameterIndex

      private int parameterIndex
    • m_wasRetried

      private boolean m_wasRetried
    • m_attributes

      private final IAttributes m_attributes
  • Constructor Details

    • TestResult

      private TestResult()
  • Method Details

    • newEmptyTestResult

      public static TestResult newEmptyTestResult()
    • newTestResultFor

      public static TestResult newTestResultFor(ITestNGMethod method)
    • newContextAwareTestResult

      public static TestResult newContextAwareTestResult(ITestNGMethod method, ITestContext ctx)
    • newTestResultWithCauseAs

      public static TestResult newTestResultWithCauseAs(ITestNGMethod method, ITestContext ctx, Throwable t)
    • newEndTimeAwareTestResult

      public static TestResult newEndTimeAwareTestResult(ITestNGMethod method, ITestContext ctx, Throwable t, long start)
    • newTestResultFrom

      public static TestResult newTestResultFrom(TestResult result, ITestNGMethod method, ITestContext ctx, long start)
    • init

      private void init(ITestNGMethod method, ITestContext ctx, Throwable t, long start, long end)
    • setEndMillis

      public void setEndMillis(long millis)
      Specified by:
      setEndMillis in interface ITestResult
    • getTestName

      public String getTestName()
      If this result's related instance implements ITest or use @Test(testName=...), returns its test name, otherwise returns null.
      Specified by:
      getTestName in interface ITestResult
      Returns:
      The test name if this result's related instance implements ITest or use @Test(testName=...), null otherwise.
    • getName

      public String getName()
      Specified by:
      getName in interface ITestResult
      Returns:
      The name of this TestResult, typically identical to the name of the method.
    • getMethod

      public ITestNGMethod getMethod()
      Specified by:
      getMethod in interface ITestResult
      Returns:
      Returns the method.
    • setMethod

      public void setMethod(ITestNGMethod method)
      Parameters:
      method - The method to set.
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface ITestResult
      Returns:
      Returns the status.
    • setStatus

      public void setStatus(int status)
      Specified by:
      setStatus in interface ITestResult
      Parameters:
      status - The status to set.
    • isSuccess

      public boolean isSuccess()
      Specified by:
      isSuccess in interface ITestResult
      Returns:
      true if if this test run is a SUCCESS
    • getTestClass

      public IClass getTestClass()
      Specified by:
      getTestClass in interface ITestResult
      Returns:
      Returns the testClass.
    • getThrowable

      public Throwable getThrowable()
      Specified by:
      getThrowable in interface ITestResult
      Returns:
      Returns the throwable.
    • setThrowable

      public void setThrowable(Throwable throwable)
      Specified by:
      setThrowable in interface ITestResult
      Parameters:
      throwable - The throwable to set.
    • getEndMillis

      public long getEndMillis()
      Specified by:
      getEndMillis in interface ITestResult
      Returns:
      Returns the endMillis.
    • getStartMillis

      public long getStartMillis()
      Specified by:
      getStartMillis in interface ITestResult
      Returns:
      Returns the startMillis.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      private static String toString(int status)
    • getHost

      public String getHost()
      Specified by:
      getHost in interface ITestResult
      Returns:
      The host where this suite was run, or null if it was run locally. The returned string has the form: host:port
    • setHost

      public void setHost(String host)
    • getParameters

      public Object[] getParameters()
      Specified by:
      getParameters in interface ITestResult
      Returns:
      The parameters this method was invoked with.
    • setParameters

      public void setParameters(Object[] parameters)
      Specified by:
      setParameters in interface ITestResult
    • getInstance

      public Object getInstance()
      Specified by:
      getInstance in interface ITestResult
      Returns:
      The instance on which this method was run.
    • getFactoryParameters

      public Object[] getFactoryParameters()
      Specified by:
      getFactoryParameters in interface ITestResult
      Returns:
      - A parameter array that was passed to a factory method (or) an empty object array otherwise.
    • getAttribute

      public Object getAttribute(String name)
      Specified by:
      getAttribute in interface IAttributes
      Parameters:
      name - The name of the attribute to return
      Returns:
      The attribute
    • setAttribute

      public void setAttribute(String name, Object value)
      Description copied from interface: IAttributes
      Set a custom attribute.
      Specified by:
      setAttribute in interface IAttributes
      Parameters:
      name - The attribute name
      value - The attribute value
    • getAttributeNames

      public Set<String> getAttributeNames()
      Specified by:
      getAttributeNames in interface IAttributes
      Returns:
      all the attributes names.
    • removeAttribute

      public Object removeAttribute(String name)
      Description copied from interface: IAttributes
      Remove the attribute
      Specified by:
      removeAttribute in interface IAttributes
      Parameters:
      name - The attribute name
      Returns:
      the attribute value if found, null otherwise
    • getTestContext

      public ITestContext getTestContext()
      Specified by:
      getTestContext in interface ITestResult
      Returns:
      the ITestContext for this test result.
    • setContext

      public void setContext(ITestContext context)
    • compareTo

      public int compareTo(@Nonnull ITestResult comparison)
      Specified by:
      compareTo in interface Comparable<ITestResult>
    • getInstanceName

      public String getInstanceName()
      Specified by:
      getInstanceName in interface ITestResult
    • setTestName

      public void setTestName(String name)
      Specified by:
      setTestName in interface ITestResult
      Parameters:
      name - - The new name to be used as a test name
    • setParameterIndex

      void setParameterIndex(int parameterIndex)
    • getParameterIndex

      public int getParameterIndex()
    • wasRetried

      public boolean wasRetried()
      Specified by:
      wasRetried in interface ITestResult
      Returns:
      - true if the test was retried again by an implementation of IRetryAnalyzer
    • setWasRetried

      public void setWasRetried(boolean wasRetried)
      Specified by:
      setWasRetried in interface ITestResult
      Parameters:
      wasRetried - - true if the test was retried and false otherwise.
    • getSkipCausedBy

      public List<ITestNGMethod> getSkipCausedBy()
      Specified by:
      getSkipCausedBy in interface ITestResult
      Returns:
      - The list of either upstream method(s) or configuration method(s) whose failure led to the current method being skipped. An empty list is returned when the current method is not a skipped method.
    • isGlobalFailure

      private static boolean isGlobalFailure(ITestResult result)
    • isRelated

      private boolean isRelated(ITestResult result)
    • belongToSameGroup

      private boolean belongToSameGroup(ITestResult result)
    • copyAttributes

      static void copyAttributes(ITestResult source, ITestResult target)