public class

AndroidJUnit3Builder

extends JUnit3Builder

 java.lang.Object

↳JUnit3Builder

↳androidx.test.internal.runner.junit3.AndroidJUnit3Builder

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.6.2'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.6.2

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

Androidx artifact mapping:

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

Overview

A that will build customized runners needed for specialized Android s.

Summary

Constructors
publicAndroidJUnit3Builder(AndroidRunnerParams runnerParams)

publicAndroidJUnit3Builder(long perTestTimeout)

Methods
public RunnerrunnerForClass(java.lang.Class<java.lang.Object> testClass)

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

Constructors

public AndroidJUnit3Builder(AndroidRunnerParams runnerParams)

Deprecated: use AndroidJUnit3Builder.AndroidJUnit3Builder(long) instead

Parameters:

runnerParams: AndroidRunnerParams that stores common runner parameters

public AndroidJUnit3Builder(long perTestTimeout)

Parameters:

perTestTimeout: milliseconds timeout value applied to each test where 0 means no timeout

Methods

public Runner runnerForClass(java.lang.Class<java.lang.Object> testClass)

Source

/*
 * Copyright (C) 2015 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.junit3;

import static androidx.test.internal.util.AndroidRunnerBuilderUtil.hasJUnit3TestMethod;
import static androidx.test.internal.util.AndroidRunnerBuilderUtil.isJUnit3Test;

import android.util.Log;
import androidx.test.internal.runner.EmptyTestRunner;
import androidx.test.internal.util.AndroidRunnerParams;
import junit.framework.TestCase;
import org.junit.internal.builders.JUnit3Builder;
import org.junit.runner.Runner;
import org.junit.runners.model.RunnerBuilder;

/**
 * A {@link RunnerBuilder} that will build customized runners needed for specialized Android {@link
 * TestCase}s.
 */
public class AndroidJUnit3Builder extends JUnit3Builder {

  private static final String TAG = "AndroidJUnit3Builder";
  private final long perTestTimeout;

  /**
   * @param runnerParams {@link AndroidRunnerParams} that stores common runner parameters
   * @deprecated use {@link AndroidJUnit3Builder(long)} instead
   */
  @Deprecated
  public AndroidJUnit3Builder(AndroidRunnerParams runnerParams) {
    this(runnerParams.getPerTestTimeout());
  }

  /**
   * @param perTestTimeout milliseconds timeout value applied to each test where 0 means no timeout
   */
  public AndroidJUnit3Builder(long perTestTimeout) {
    this.perTestTimeout = perTestTimeout;
  }

  @Override
  public Runner runnerForClass(Class<?> testClass) throws Throwable {
    try {
      if (isJUnit3Test(testClass)) {
        if (!hasJUnit3TestMethod(testClass)) {
          // ideally we would just let JUnit38ClassRunner handle this case, but for historical
          // reasons there was special handling when classpath scanning for this case
          return new EmptyTestRunner(testClass);
        }
        return new JUnit38ClassRunner(new AndroidTestSuite(testClass, perTestTimeout));
      }
    } catch (Throwable e) {
      // log error message including stack trace before throwing to help with debugging.
      Log.e(TAG, "Error constructing runner", e);
      throw e;
    }
    return null;
  }
}