public final class

TestCaseStartedEvent

extends TestPlatformEvent

 java.lang.Object

androidx.test.services.events.platform.TestPlatformEvent

↳androidx.test.services.events.platform.TestCaseStartedEvent

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 the start of an individual test case. One TestCaseStartedEvent should always be emitted for each individual test case in a test run. However, there are a couple of test statuses that do not require an explicit TestCaseStartedEvent.

  • : The test was never started and will not be run.
  • : The test was supposed to run, but this client encountered a state that required it to exit before the test could run.

Summary

Fields
public final TestCaseInfotestCase

The test case that started.

public final TimeStamptimeStamp

The time this test case started.

from TestPlatformEventCREATOR
Constructors
publicTestCaseStartedEvent(Parcel source)

Creates a TestCaseStartedEvent from an .

publicTestCaseStartedEvent(TestCaseInfo testCase, TimeStamp timeStamp)

Creates a TestCaseStartedEvent.

Methods
abstract TestPlatformEvent.EventTypeinstanceType()

The ITestPlatformEvent#send(TestPlatformEvent) service method receives an instance of the TestPlatformEvent base class, so the TestPlatformEvent.CREATOR factory in this class is being used to create the event instances, not the CREATOR of one of its derived instances.

public voidwriteToParcel(Parcel parcel, int i)

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

Fields

public final TestCaseInfo testCase

The test case that started.

public final TimeStamp timeStamp

The time this test case started.

Constructors

public TestCaseStartedEvent(TestCaseInfo testCase, TimeStamp timeStamp)

Creates a TestCaseStartedEvent.

Parameters:

testCase: the test case that started.
timeStamp: the time the test case began.

public TestCaseStartedEvent(Parcel source)

Creates a TestCaseStartedEvent from an .

Parameters:

source: to create the TestCaseStartedEvent from.

Methods

public void writeToParcel(Parcel parcel, int i)

abstract TestPlatformEvent.EventType instanceType()

The ITestPlatformEvent#send(TestPlatformEvent) service method receives an instance of the TestPlatformEvent base class, so the TestPlatformEvent.CREATOR factory in this class is being used to create the event instances, not the CREATOR of one of its derived instances.

Therefore the createFromParcel method first needs to read a String containing the EventType enum value of the correct derived type to instantiate. Derived classes should override this method to return the applicable event type.

Also note that this means only this base class provides a CREATOR, since the derived classes don't need one.

Returns:

the EventType of the final derived event class that extends this base class

Source

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

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

import android.os.Parcel;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.test.services.events.TestCaseInfo;
import androidx.test.services.events.TimeStamp;

/**
 * Represents the start of an individual test case. One {@link TestCaseStartedEvent} should always
 * be emitted for each individual test case in a test run. However, there are a couple of test
 * statuses that do not require an explicit {@link TestCaseStartedEvent}.
 *
 * <ul>
 *   <li>{@link androidx.test.services.events.TestStatus.Status.IGNORED}: The test was never started
 *       and will not be run.
 *   <li>{@link androidx.test.services.events.TestStatus.Status.CANCELLED}: The test was supposed to
 *       run, but this client encountered a state that required it to exit before the test could
 *       run.
 * </ul>
 *
 * @see TestCaseFinishedEvent to indicate the end of a test case
 * @see TestCaseErrorEvent for reporting various errors encountered during a test run.
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final class TestCaseStartedEvent extends TestPlatformEvent {
  /** The test case that started. */
  @NonNull public final TestCaseInfo testCase;
  /** The time this test case started. */
  @NonNull public final TimeStamp timeStamp;

  /**
   * Creates a {@link TestCaseStartedEvent}.
   *
   * @param testCase the test case that started.
   * @param timeStamp the time the test case began.
   */
  public TestCaseStartedEvent(@NonNull TestCaseInfo testCase, @NonNull TimeStamp timeStamp) {
    this.testCase = checkNotNull(testCase, "testCase cannot be null");
    this.timeStamp = checkNotNull(timeStamp, "timeStamp cannot be null");
  }

  /**
   * Creates a {@link TestCaseStartedEvent} from an {@link Parcel}.
   *
   * @param source {@link Parcel} to create the {@link TestCaseStartedEvent} from.
   */
  public TestCaseStartedEvent(Parcel source) {
    testCase = new TestCaseInfo(source);
    timeStamp = new TimeStamp(source);
  }

  @Override
  public void writeToParcel(Parcel parcel, int i) {
    super.writeToParcel(parcel, i);
    testCase.writeToParcel(parcel, i);
    timeStamp.writeToParcel(parcel, i);
  }

  @Override
  public EventType instanceType() {
    return EventType.TEST_CASE_STARTED;
  }
}