public final class

TestCaseInfo

extends java.lang.Object

 java.lang.Object

↳androidx.test.services.events.TestCaseInfo

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

Represents a parcelable TestCase. Contains all the information for a test case. Each test method inside a Java test is considered a separate TestCaseInfo. The TestCaseInfo is used to serialize and send Java test case information between the test runner and the remote ITestRunEvent and ITestDiscoveryEvent Android Services.

See Android Parcelable.

Summary

Fields
public final java.util.List<AnnotationInfo>classAnnotations

Annotations on the test class.

public final java.lang.StringclassName

Name of the test class.

public static final <any>CREATOR

public final java.util.List<AnnotationInfo>methodAnnotations

Annotations on the test method.

public final java.lang.StringmethodName

Name of the test method.

Constructors
publicTestCaseInfo(Parcel source)

Creates an AnnotationInfo from an Android .

publicTestCaseInfo(java.lang.String className, java.lang.String methodName, java.util.List<AnnotationInfo> methodAnnotations, java.util.List<AnnotationInfo> classAnnotations)

Creates a TestCaseInfo.

Methods
public intdescribeContents()

public java.lang.StringgetClassAndMethodName()

public voidwriteToParcel(Parcel parcel, int i)

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

Fields

public final java.lang.String className

Name of the test class.

public final java.lang.String methodName

Name of the test method.

public final java.util.List<AnnotationInfo> methodAnnotations

Annotations on the test method.

public final java.util.List<AnnotationInfo> classAnnotations

Annotations on the test class.

public static final <any> CREATOR

Constructors

public TestCaseInfo(Parcel source)

Creates an AnnotationInfo from an Android .

Parameters:

source: Android to read from

public TestCaseInfo(java.lang.String className, java.lang.String methodName, java.util.List<AnnotationInfo> methodAnnotations, java.util.List<AnnotationInfo> classAnnotations)

Creates a TestCaseInfo.

Parameters:

className: Name of the test class
methodName: Name of the test method
methodAnnotations: Annotations on the test method
classAnnotations: Annotations on the test class

Methods

public java.lang.String getClassAndMethodName()

public int describeContents()

public void writeToParcel(Parcel parcel, int i)

Source

/*
 * Copyright (C) 2019 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.services.events;

import static androidx.test.internal.util.Checks.checkNotNull;

import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents a parcelable TestCase. Contains all the information for a test case. Each test method
 * inside a Java test is considered a separate {@link TestCaseInfo}. The {@link TestCaseInfo} is
 * used to serialize and send Java test case information between the test runner and the remote
 * {@link androidx.test.services.events.run.ITestRunEvent} and {@link
 * androidx.test.services.events.discovery.ITestDiscoveryEvent} Android Services.
 *
 * <p>See <a href="https://developer.android.com/reference/android/os/Parcelable.html">Android
 * Parcelable</a>.
 *
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final class TestCaseInfo implements Parcelable {
  /** Name of the test class. */
  @NonNull public final String className;
  /** Name of the test method. */
  @NonNull public final String methodName;
  /** Annotations on the test method. */
  @NonNull public final List<AnnotationInfo> methodAnnotations;
  /** Annotations on the test class. */
  @NonNull public final List<AnnotationInfo> classAnnotations;

  /**
   * Creates an {@link AnnotationInfo} from an Android {@link Parcel}.
   *
   * @param source Android {@link Parcel} to read from
   */
  public TestCaseInfo(@NonNull Parcel source) {
    checkNotNull(source, "source cannot be null");
    className = checkNotNull(source.readString(), "className cannot be null");
    methodName = checkNotNull(source.readString(), "methodName cannot be null");
    methodAnnotations = new ArrayList<>();
    source.readTypedList(methodAnnotations, AnnotationInfo.CREATOR);
    classAnnotations = new ArrayList<>();
    source.readTypedList(classAnnotations, AnnotationInfo.CREATOR);
  }

  /**
   * Creates a {@link TestCaseInfo}.
   *
   * @param className Name of the test class
   * @param methodName Name of the test method
   * @param methodAnnotations Annotations on the test method
   * @param classAnnotations Annotations on the test class
   */
  public TestCaseInfo(
      @NonNull String className,
      @NonNull String methodName,
      @NonNull List<AnnotationInfo> methodAnnotations,
      @NonNull List<AnnotationInfo> classAnnotations) {
    this.className = checkNotNull(className, "className cannot be null");
    this.methodName = checkNotNull(methodName, "methodName cannot be null");
    this.classAnnotations = checkNotNull(classAnnotations, "classAnnotations cannot be null");
    this.methodAnnotations = checkNotNull(methodAnnotations, "methodAnnotations cannot be null");
  }

  @NonNull
  public String getClassAndMethodName() {
    return className + "#" + methodName;
  }

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(className);
    parcel.writeString(methodName);
    parcel.writeTypedList(methodAnnotations);
    parcel.writeTypedList(classAnnotations);
  }

  public static final Parcelable.Creator<TestCaseInfo> CREATOR =
      new Parcelable.Creator<TestCaseInfo>() {
        @Override
        public TestCaseInfo createFromParcel(Parcel source) {
          return new TestCaseInfo(source);
        }

        @Override
        public TestCaseInfo[] newArray(int size) {
          return new TestCaseInfo[size];
        }
      };
}