public class

TestResult

extends java.lang.Object

 java.lang.Object

↳androidx.test.orchestrator.listeners.result.TestResult

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.5.0-alpha03'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.5.0-alpha03

Artifact androidx.test:runner:1.5.0-alpha03 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:runner com.android.support.test:runner

Androidx class mapping:

androidx.test.orchestrator.listeners.result.TestResult android.support.test.orchestrator.listeners.result.TestResult

Overview

Container for a result of a single test.

This is a copy of com.android.ddmlib.testrunner.TestResult.

Summary

Constructors
publicTestResult()

Methods
public booleanequals(java.lang.Object obj)

public longgetEndTime()

Return the currentTimeMillis time that the ITestRunListener.testEnded(TestIdentifier, Map) event was received.

public java.util.Map<java.lang.String, java.lang.String>getMetrics()

Get the associated test metrics.

public java.lang.StringgetStackTrace()

Get the associated java.lang.String stack trace.

public longgetStartTime()

Return the currentTimeMillis time that the ITestRunListener.testStarted(TestIdentifier) event was received.

public TestResult.TestStatusgetStatus()

Get the TestResult.TestStatus result of the test.

public inthashCode()

public voidsetEndTime(long currentTimeMillis)

Sets the end time

public voidsetMetrics(java.util.Map<java.lang.String, java.lang.String> metrics)

Set the test metrics, overriding any previous values.

public voidsetStackTrace(java.lang.String trace)

Set the stack trace.

public TestResultsetStatus(TestResult.TestStatus status)

Set the TestResult.TestStatus.

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

Constructors

public TestResult()

Methods

public TestResult.TestStatus getStatus()

Get the TestResult.TestStatus result of the test.

public java.lang.String getStackTrace()

Get the associated java.lang.String stack trace. Should be null if TestResult.getStatus() is TestResult.TestStatus.PASSED.

public java.util.Map<java.lang.String, java.lang.String> getMetrics()

Get the associated test metrics.

public void setMetrics(java.util.Map<java.lang.String, java.lang.String> metrics)

Set the test metrics, overriding any previous values.

public long getStartTime()

Return the currentTimeMillis time that the ITestRunListener.testStarted(TestIdentifier) event was received.

public long getEndTime()

Return the currentTimeMillis time that the ITestRunListener.testEnded(TestIdentifier, Map) event was received.

public TestResult setStatus(TestResult.TestStatus status)

Set the TestResult.TestStatus.

public void setStackTrace(java.lang.String trace)

Set the stack trace.

public void setEndTime(long currentTimeMillis)

Sets the end time

public int hashCode()

public boolean equals(java.lang.Object obj)

Source

/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.test.orchestrator.listeners.result;

import androidx.test.orchestrator.listeners.result.TestResult.TestStatus;
import java.util.Arrays;
import java.util.Map;

/**
 * Container for a result of a single test.
 *
 * <p>This is a copy of {@code com.android.ddmlib.testrunner.TestResult}.
 */
public class TestResult {

  public enum TestStatus {
    /** Test failed. */
    FAILURE,
    /** Test passed */
    PASSED,
    /** Test started but not ended */
    INCOMPLETE,
    /** Test assumption failure */
    ASSUMPTION_FAILURE,
    /** Test ignored */
    IGNORED,
  }

  private TestStatus status;
  private String stackTrace;
  private Map<String, String> metrics;
  // the start and end time of the test, measured via {@link System#currentTimeMillis()}
  private long startTime = 0;
  private long endTime = 0;

  public TestResult() {
    status = TestStatus.INCOMPLETE;
    startTime = System.currentTimeMillis();
  }

  /** Get the {@link TestStatus} result of the test. */
  public TestStatus getStatus() {
    return status;
  }

  /**
   * Get the associated {@link String} stack trace. Should be <code>null</code> if {@link
   * #getStatus()} is {@link TestStatus#PASSED}.
   */
  public String getStackTrace() {
    return stackTrace;
  }

  /** Get the associated test metrics. */
  public Map<String, String> getMetrics() {
    return metrics;
  }

  /** Set the test metrics, overriding any previous values. */
  public void setMetrics(Map<String, String> metrics) {
    this.metrics = metrics;
  }

  /**
   * Return the {@link System#currentTimeMillis()} time that the {@link
   * ITestRunListener#testStarted(TestIdentifier)} event was received.
   */
  public long getStartTime() {
    return startTime;
  }

  /**
   * Return the {@link System#currentTimeMillis()} time that the {@link
   * ITestRunListener#testEnded(TestIdentifier, Map)} event was received.
   */
  public long getEndTime() {
    return endTime;
  }

  /** Set the {@link TestStatus}. */
  public TestResult setStatus(TestStatus status) {
    this.status = status;
    return this;
  }

  /** Set the stack trace. */
  public void setStackTrace(String trace) {
    stackTrace = trace;
  }

  /** Sets the end time */
  public void setEndTime(long currentTimeMillis) {
    endTime = currentTimeMillis;
  }

  @Override
  public int hashCode() {
    return Arrays.hashCode(new Object[] {metrics, stackTrace, status});
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    TestResult other = (TestResult) obj;
    return equal(metrics, other.metrics)
        && equal(stackTrace, other.stackTrace)
        && equal(status, other.status);
  }

  private static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }
}