public abstract class

TestLoader

extends java.lang.Object

 java.lang.Object

↳androidx.test.internal.runner.TestLoader

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

An abstract class for loading JUnit3 and JUnit4 test classes given a set of potential class names.

Summary

Constructors
publicTestLoader()

Methods
protected abstract RunnerdoCreateRunner(java.lang.String className)

public java.util.List<Runner>getRunnersFor(java.util.Collection<java.lang.String> classNames)

Get the Collection) of {@link Runner runners}.

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

Constructors

public TestLoader()

Methods

protected abstract Runner doCreateRunner(java.lang.String className)

public java.util.List<Runner> getRunnersFor(java.util.Collection<java.lang.String> classNames)

Get the Collection) of {@link Runner runners}.

Source

/*
 * Copyright (C) 2012 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;

import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.runner.Runner;
import org.junit.runners.model.RunnerBuilder;

/**
 * An abstract class for loading JUnit3 and JUnit4 test classes given a set of potential class
 * names.
 */
public abstract class TestLoader {

  /** Factory for {@link TestLoader} */
  public static class Factory {

    private Factory() {}

    public static TestLoader create(
        @Nullable ClassLoader classLoader, RunnerBuilder runnerBuilder, boolean scanningPath) {

      if (classLoader == null) {
        classLoader = TestLoader.class.getClassLoader();
      }

      if (scanningPath) {
        return new ScanningTestLoader(classLoader, runnerBuilder);
      } else {
        return new DirectTestLoader(classLoader, runnerBuilder);
      }
    }
  }

  protected abstract Runner doCreateRunner(String className);

  /**
   * Get the {@link Collection) of {@link Runner runners}.
   */
  public List<Runner> getRunnersFor(Collection<String> classNames) {
    final Map<String, Runner> runnersMap = new LinkedHashMap<>();

    for (String className : classNames) {
      if (!runnersMap.containsKey(className)) {
        Runner runner = doCreateRunner(className);
        if (runner != null) {
          runnersMap.put(className, runner);
        }
      }
    }
    return new ArrayList<>(runnersMap.values());
  }
}