public class TestCarContext
extends CarContext

   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ androidx.car.app.CarContext
         ↳ androidx.car.app.testing.TestCarContext

The CarContext that is used for testing.

This class will return the test version of car services for tracking calls during testing.

It also allows retrieving the car services already cast to the testing class by calling getCarService(Class) with the class name of the test services:


Allows retrieving all Intents sent via CarContext.startCarApp(Intent).


Nested classes

class TestCarContext.PermissionRequestInfo

A representation of a permission request including the permissions that were requested as well as the callback provided. 

Inherited constants

Public methods

static TestCarContext createCarContext(Context testContext)

Creates a TestCarContext to use for testing.

void finishCarApp()

Requests to finish the car app.

<T> T getCarService(Class<T> serviceClass)

Returns a car service by class.

Object getCarService(String name)

Provides a car service by name.

FakeHost getFakeHost()

Retrieve the FakeHost being used.

TestCarContext.PermissionRequestInfo getLastPermissionRequestInfo()

Returns a TestCarContext.PermissionRequestInfo including the information with the last call made to CarContext.requestPermissions(List, OnRequestPermissionsListener), or null if no call was made.

List<Intent> getStartCarAppIntents()

Returns all Intents sent via CarContext.startCarApp(Intent).

boolean hasCalledFinishCarApp()

Verifies if CarContext.finishCarApp() has been called.

void requestPermissions(List<String> permissions, Executor executor, OnRequestPermissionsListener listener)

Requests the provided permissions from the user.

void reset()

Resets the values tracked by this TestCarContext.

void startCarApp(Intent intent)

Starts a car app on the car screen.

Inherited methods