public class

SuiteAssignmentPrinter

extends InstrumentationRunListener

 java.lang.Object

↳RunListener

androidx.test.internal.runner.listener.InstrumentationRunListener

↳androidx.test.internal.runner.listener.SuiteAssignmentPrinter

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

Overview

This class measures the elapsed run time of each test, and used it to report back to the user which suite (SmallTest, MediumTest, LargeTest) the test should belong to.

Summary

Constructors
publicSuiteAssignmentPrinter()

Methods
public longgetCurrentTimeMillis()

public voidtestAssumptionFailure(Failure failure)

public voidtestFailure(Failure failure)

public voidtestFinished(Description description)

public voidtestIgnored(Description description)

public voidtestStarted(Description description)

from InstrumentationRunListenergetInstrumentation, instrumentationRunFinished, sendStatus, sendString, setInstrumentation
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SuiteAssignmentPrinter()

Methods

public void testStarted(Description description)

public void testFinished(Description description)

public void testFailure(Failure failure)

public void testAssumptionFailure(Failure failure)

public void testIgnored(Description description)

public long getCurrentTimeMillis()

Source

/*
 * Copyright (C) 2016 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.internal.runner.listener;

import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.test.internal.runner.TestSize;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;

/**
 * This class measures the elapsed run time of each test, and used it to report back to the user
 * which suite ({@link androidx.test.filters.SmallTest}, {@link
 * androidx.test.filters.MediumTest}, {@link androidx.test.filters.LargeTest}) the
 * test should belong to.
 */
public class SuiteAssignmentPrinter extends InstrumentationRunListener {

  @VisibleForTesting long startTime;
  @VisibleForTesting long endTime;
  @VisibleForTesting boolean timingValid;

  @Override
  public void testStarted(Description description) throws Exception {
    timingValid = true;
    startTime = getCurrentTimeMillis();
  }

  @Override
  public void testFinished(Description description) throws Exception {
    long runTime;
    endTime = getCurrentTimeMillis();

    if (!timingValid || startTime < 0) {
      sendString("F");
      Log.d(
          "SuiteAssignmentPrinter",
          String.format(
              "%s#%s: skipping suite assignment due to test failure\n",
              description.getClassName(), description.getMethodName()));
    } else {
      runTime = endTime - startTime;
      TestSize assignmentSuite = TestSize.getTestSizeForRunTime(runTime);
      TestSize currentRenameSize = TestSize.fromDescription(description);
      if (!assignmentSuite.equals(currentRenameSize)) {
        // test size != runtime
        sendString(
            String.format(
                "\n%s#%s: current size: %s. suggested: %s runTime: %d ms\n",
                description.getClassName(),
                description.getMethodName(),
                currentRenameSize,
                assignmentSuite.getSizeQualifierName(),
                runTime));
      } else {
        sendString(".");
        Log.d(
            "SuiteAssignmentPrinter",
            String.format(
                "%s#%s assigned correctly as %s. runTime: %d ms\n",
                description.getClassName(),
                description.getMethodName(),
                assignmentSuite.getSizeQualifierName(),
                runTime));
      }
    }
    // Clear startTime so that we can verify that it gets set next time.
    startTime = -1;
  }

  @Override
  public void testFailure(Failure failure) throws Exception {
    timingValid = false;
  }

  @Override
  public void testAssumptionFailure(Failure failure) {
    timingValid = false;
  }

  @Override
  public void testIgnored(Description description) throws Exception {
    timingValid = false;
  }

  @VisibleForTesting
  public long getCurrentTimeMillis() {
    return System.currentTimeMillis();
  }
}