# XrDeviceTestRule

Artifact: [androidx.xr.runtime:runtime-testing](https://developer.android.com/jetpack/androidx/releases/xr-runtime) [View Source](https://cs.android.com/search?q=file:androidx/xr/runtime/testing/XrDeviceTestRule.kt+class:androidx.xr.runtime.testing.XrDeviceTestRule) Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

*** ** * ** ***


```
public final class XrDeviceTestRule extends ExternalResource
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [org.junit.rules.ExternalResource](https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html) ||
|   | ↳ | [androidx.xr.runtime.testing.XrDeviceTestRule](https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule) |

*** ** * ** ***

JUnit Rule containing properties that affect the results of `https://developer.android.com/reference/androidx/xr/runtime/XrDevice` capability APIs.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#XrDeviceTestRule()()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getLifecycleState()()` Tests can set this property to control the lifecycle state of the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/DisplayBlendMode` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getPreferredDisplayBlendMode()()` The result of `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#getPreferredDisplayBlendMode()`. |
| `final int` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getSpatialApiVersion()()` The value to be returned by `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/DepthEstimationMode>` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getSupportedDepthEstimationModes()()` The set of `https://developer.android.com/reference/androidx/xr/runtime/DepthEstimationMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/EyeTrackingMode>` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getSupportedEyeTrackingModes()()` The set of `https://developer.android.com/reference/androidx/xr/runtime/EyeTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/GeospatialMode>` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getSupportedGeospatialModes()()` The set of `https://developer.android.com/reference/androidx/xr/runtime/GeospatialMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/HandTrackingMode>` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getSupportedHandTrackingModes()()` The set of `https://developer.android.com/reference/androidx/xr/runtime/HandTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/RenderingMode>` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#getSupportedRenderingModes()()` The set of `https://developer.android.com/reference/androidx/xr/runtime/RenderingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final boolean` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#isProjectedServiceAvailable()()` This property can be used to control whether the Projected service is available or not. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setLifecycleState(androidx.lifecycle.Lifecycle.State)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State value)` Tests can set this property to control the lifecycle state of the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setPreferredDisplayBlendMode(androidx.xr.runtime.DisplayBlendMode)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/DisplayBlendMode value)` The result of `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#getPreferredDisplayBlendMode()`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setProjectedServiceAvailable(kotlin.Boolean)(boolean value)` This property can be used to control whether the Projected service is available or not. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setSpatialApiVersion(kotlin.Int)(int value)` The value to be returned by `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setSupportedDepthEstimationModes(kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/DepthEstimationMode> value )` The set of `https://developer.android.com/reference/androidx/xr/runtime/DepthEstimationMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setSupportedEyeTrackingModes(kotlin.collections.Set)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/EyeTrackingMode> value)` The set of `https://developer.android.com/reference/androidx/xr/runtime/EyeTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setSupportedGeospatialModes(kotlin.collections.Set)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/GeospatialMode> value)` The set of `https://developer.android.com/reference/androidx/xr/runtime/GeospatialMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setSupportedHandTrackingModes(kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/HandTrackingMode> value )` The set of `https://developer.android.com/reference/androidx/xr/runtime/HandTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#setSupportedRenderingModes(kotlin.collections.Set)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/RenderingMode> value)` The set of `https://developer.android.com/reference/androidx/xr/runtime/RenderingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#after()()` |
| `void` | `https://developer.android.com/reference/androidx/xr/runtime/testing/XrDeviceTestRule#before()()` |

### Inherited methods

From [org.junit.rules.ExternalResource](https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html) `@https://developer.android.com/reference/androidx/annotation/NonNull https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html` `https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html#apply-org.junit.runners.model.Statement-org.junit.runner.Description-(@https://developer.android.com/reference/androidx/annotation/NonNull https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html base, @https://developer.android.com/reference/androidx/annotation/NonNull https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html description)`

## Public constructors

### XrDeviceTestRule

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public XrDeviceTestRule()
```

## Public methods

### getLifecycleState

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull Lifecycle.State getLifecycleState()
```

Tests can set this property to control the lifecycle state of the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. By default, the value is set to `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#INITIALIZED`.

### getPreferredDisplayBlendMode

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull DisplayBlendMode getPreferredDisplayBlendMode()
```

The result of `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#getPreferredDisplayBlendMode()`.

Tests can set this property to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#getPreferredDisplayBlendMode()` during the test execution.

### getSpatialApiVersion

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final int getSpatialApiVersion()
```

The value to be returned by `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()`.

Tests can set this property to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()` during the test execution. By default the value is set to the latest stable API level.

### getSupportedDepthEstimationModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull Set<@NonNull DepthEstimationMode> getSupportedDepthEstimationModes()
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/DepthEstimationMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isDepthEstimationModeSupported(androidx.xr.runtime.DepthEstimationMode)` during the test execution.

### getSupportedEyeTrackingModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull Set<@NonNull EyeTrackingMode> getSupportedEyeTrackingModes()
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/EyeTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isEyeTrackingModeSupported(androidx.xr.runtime.EyeTrackingMode)` during the test execution.

### getSupportedGeospatialModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull Set<@NonNull GeospatialMode> getSupportedGeospatialModes()
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/GeospatialMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isGeospatialModeSupported(androidx.xr.runtime.GeospatialMode)` during the test execution.

### getSupportedHandTrackingModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull Set<@NonNull HandTrackingMode> getSupportedHandTrackingModes()
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/HandTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isHandTrackingModeSupported(androidx.xr.runtime.HandTrackingMode)` during the test execution.

### getSupportedRenderingModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final @NonNull Set<@NonNull RenderingMode> getSupportedRenderingModes()
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/RenderingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isRenderingModeSupported(androidx.xr.runtime.RenderingMode)` during the test execution.

### isProjectedServiceAvailable

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final boolean isProjectedServiceAvailable()
```

This property can be used to control whether the Projected service is available or not. By default, the Projected service is available.

### setLifecycleState

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setLifecycleState(@NonNull Lifecycle.State value)
```

Tests can set this property to control the lifecycle state of the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`. By default, the value is set to `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#INITIALIZED`.

### setPreferredDisplayBlendMode

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setPreferredDisplayBlendMode(@NonNull DisplayBlendMode value)
```

The result of `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#getPreferredDisplayBlendMode()`.

Tests can set this property to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#getPreferredDisplayBlendMode()` during the test execution.

### setProjectedServiceAvailable

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setProjectedServiceAvailable(boolean value)
```

This property can be used to control whether the Projected service is available or not. By default, the Projected service is available.

### setSpatialApiVersion

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setSpatialApiVersion(int value)
```

The value to be returned by `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()`.

Tests can set this property to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()` during the test execution. By default the value is set to the latest stable API level.

### setSupportedDepthEstimationModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setSupportedDepthEstimationModes(
    @NonNull Set<@NonNull DepthEstimationMode> value
)
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/DepthEstimationMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isDepthEstimationModeSupported(androidx.xr.runtime.DepthEstimationMode)` during the test execution.

### setSupportedEyeTrackingModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setSupportedEyeTrackingModes(@NonNull Set<@NonNull EyeTrackingMode> value)
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/EyeTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isEyeTrackingModeSupported(androidx.xr.runtime.EyeTrackingMode)` during the test execution.

### setSupportedGeospatialModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setSupportedGeospatialModes(@NonNull Set<@NonNull GeospatialMode> value)
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/GeospatialMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isGeospatialModeSupported(androidx.xr.runtime.GeospatialMode)` during the test execution.

### setSupportedHandTrackingModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setSupportedHandTrackingModes(
    @NonNull Set<@NonNull HandTrackingMode> value
)
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/HandTrackingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isHandTrackingModeSupported(androidx.xr.runtime.HandTrackingMode)` during the test execution.

### setSupportedRenderingModes

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
public final void setSupportedRenderingModes(@NonNull Set<@NonNull RenderingMode> value)
```

The set of `https://developer.android.com/reference/androidx/xr/runtime/RenderingMode` instances supported by the `https://developer.android.com/reference/androidx/xr/runtime/XrDevice`.

Tests can modify this set to control the value returned by `https://developer.android.com/reference/androidx/xr/runtime/XrDevice#isRenderingModeSupported(androidx.xr.runtime.RenderingMode)` during the test execution.

## Protected methods

### after

```
protected void after()
```

### before

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

```
protected void before()
```