package org.testng;

import java.util.Collections;
import java.util.List;
import org.testng.internal.thread.ThreadTimeoutException;

This class describes the result of a test.
Author:Cedric Beust, May 2, 2004
Version:$Revision: 721 $, $Date: 2009-05-23 09:55:46 -0700 (Sat, 23 May 2009) $
Since:May 2, 2004
/** * This class describes the result of a test. * * @author Cedric Beust, May 2, 2004 * @version $Revision: 721 $, $Date: 2009-05-23 09:55:46 -0700 (Sat, 23 May 2009) $ * @since May 2, 2004 */
public interface ITestResult extends IAttributes, Comparable<ITestResult> { // Test status int CREATED = -1; int SUCCESS = 1; int FAILURE = 2; int SKIP = 3; int SUCCESS_PERCENTAGE_FAILURE = 4; int STARTED = 16;
Returns:The status of this result, using one of the constants above.
/** @return The status of this result, using one of the constants above. */
int getStatus(); void setStatus(int status);
Returns:The test method this result represents.
/** @return The test method this result represents. */
ITestNGMethod getMethod();
Returns:The parameters this method was invoked with.
/** @return The parameters this method was invoked with. */
Object[] getParameters(); void setParameters(Object[] parameters);
Returns:The test class used this object is a result for.
/** @return The test class used this object is a result for. */
IClass getTestClass();
Returns:The throwable that was thrown while running the method, or null if no exception was thrown.
/** * @return The throwable that was thrown while running the method, or null if no exception was * thrown. */
Throwable getThrowable(); void setThrowable(Throwable throwable);
Returns:the start date for this test, in milliseconds.
/** @return the start date for this test, in milliseconds. */
long getStartMillis();
Returns:the end date for this test, in milliseconds.
/** @return the end date for this test, in milliseconds. */
long getEndMillis(); void setEndMillis(long millis);
Returns:The name of this TestResult, typically identical to the name of the method.
/** @return The name of this TestResult, typically identical to the name of the method. */
String getName();
Returns:true if if this test run is a SUCCESS
/** @return true if if this test run is a SUCCESS */
boolean isSuccess();
Returns:The host where this suite was run, or null if it was run locally. The returned string has the form: host:port
/** * @return The host where this suite was run, or null if it was run locally. The returned string * has the form: host:port */
String getHost();
Returns:The instance on which this method was run.
/** @return The instance on which this method was run. */
Object getInstance();
Returns:- A parameter array that was passed to a factory method (or) an empty object array otherwise.
/** * @return - A parameter array that was passed to a factory method (or) an empty object array * otherwise. */
Object[] getFactoryParameters();
Returns:The test name if this result's related instance implements ITest or use @Test(testName=...), null otherwise.
/** * @return The test name if this result's related instance implements ITest or use @Test(testName=...), * null otherwise. */
String getTestName(); String getInstanceName();
Returns:the ITestContext for this test result.
/** @return the {@link ITestContext} for this test result. */
ITestContext getTestContext();
Params:
  • name – - The new name to be used as a test name
/** @param name - The new name to be used as a test name */
void setTestName(String name);
Returns:- true if the test was retried again by an implementation of IRetryAnalyzer
/** * @return - <code>true</code> if the test was retried again by an implementation of {@link * IRetryAnalyzer} */
boolean wasRetried();
Params:
  • wasRetried – - true if the test was retried and false otherwise.
/** * @param wasRetried - <code>true</code> if the test was retried and <code>false</code> otherwise. */
void setWasRetried(boolean wasRetried);
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.
/** * @return - 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. */
default List<ITestNGMethod> getSkipCausedBy() { return Collections.emptyList(); }
Params:
  • result – - The test result of a method
Returns:- true if the test failure was due to a timeout.
/** * @param result - The test result of a method * @return - <code>true</code> if the test failure was due to a timeout. */
static boolean wasFailureDueToTimeout(ITestResult result) { Throwable cause = result.getThrowable(); while (cause != null && !cause.getClass().equals(Throwable.class)) { if (cause instanceof ThreadTimeoutException) { return true; } cause = cause.getCause(); } return false; } }