# SceneCoreTestRule

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

*** ** * ** ***


```
class SceneCoreTestRule : ExternalResource
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [org.junit.rules.ExternalResource](https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html) ||
|   | ↳ | [androidx.xr.scenecore.testing.SceneCoreTestRule](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule) |

*** ** * ** ***

A JUnit Rule for establishing a test environment for SceneCore applications.

This rule provides fake implementations and test accessors for SceneCore components, allowing you to configure and verify the internal runtime states of SceneCore's public API objects like `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` and `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component`.

To enable the test rule to manage the lifecycle and state of SceneCore objects, you must register the created instance with the rule after its creation using the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Entity)` method provided by this rule. These methods return test-specific accessors that allow inspection and manipulation of the underlying fake instance.

Example usage:

```kotlin
@Rule @JvmField val testRule = SceneCoreTestRule()

// Inside a test method:
// Create a SceneCore Entity
val entity = PanelEntity.create(...)
// Register it with the rule and get the test accessor
val entityTester = testRule.createTester<PanelEntityTester>(entity)
// Use entityTester to interact with the entity's state

// Create a SceneCore Component
val component = MovableComponent.create(...)
// Register it and get the test accessor
val componentTester = testRule.createTester<MovableComponentTester>(component)
// Use componentTester to interact with the component's state
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#SceneCoreTestRule()()` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/ImageBasedLightingAssetTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.ImageBasedLightingAsset)(asset: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ImageBasedLightingAsset)` Creates a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ImageBasedLightingAsset`. |
| `inline T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Component)(component: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component)` Creates a specific test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component`. |
| `inline T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Creates a specific test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/GltfModelTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.GltfModel)(gltfModel: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModel)` Retrieves a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModel`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialMediaPlayerTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(android.media.MediaPlayer)(mediaPlayer: https://developer.android.com/reference/android/media/MediaPlayer.html)` Creates the test data accessor for the given `https://developer.android.com/reference/android/media/MediaPlayer.html`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SoundEffectPoolTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.SoundEffectPool)(soundEffectPool: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool)` Retrieves a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/TextureTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Texture)(texture: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture)` Creates a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`. |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#after()()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#before()()` |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/ActivitySpaceTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#activitySpaceTester()` Provides the instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/ActivitySpaceTester` which is a test data accessor of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/MainPanelEntityTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#mainPanelEntityTester()` Provides the test-only accessor for `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MainPanelEntity` that enables direct manipulation and inspection of its internal state. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/PerceptionSpaceTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#perceptionSpaceTester()` Provides the instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/PerceptionSpaceTester` which is a test data accessor of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PerceptionSpace`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#sceneTester()` Provides access to a controller for simulating runtime spatial states of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Scene`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialAudioTrackBuilderTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#spatialAudioTrackBuilderTester()` Provides the test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialAudioTrackBuilder`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialAudioTrackTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#spatialAudioTrackTester()` Provides the test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialAudioTrack`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialEnvironmentTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#spatialEnvironmentTester()` The test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialEnvironment`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialSoundPoolTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#spatialSoundPoolTester()` This provides a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialSoundPoolTester` instance for accessing the SpatialSoundPool's underlying fake test data. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialWindowTester` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#spatialWindowTester()` Provides the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialWindowTester` test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialWindow`. |

### Inherited functions

From [org.junit.rules.ExternalResource](https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html) `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-(base: https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html, description: https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html)`

## Public constructors

### SceneCoreTestRule

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

```
SceneCoreTestRule()
```

## Public functions

### createTester

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

```
fun createTester(asset: ImageBasedLightingAsset): ImageBasedLightingAssetTester
```

Creates a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ImageBasedLightingAsset`.

In the test environment, each asset created via `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ImageBasedLightingAsset.Companion#createFromZip(androidx.xr.runtime.Session,androidx.xr.scenecore.runtime.RenderingRuntime,kotlin.String)` has corresponding underlying fake data. This function provides access to that fake data, allowing for verification or manipulation in tests.

| Parameters |
|---|---|
| `asset: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ImageBasedLightingAsset` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ImageBasedLightingAsset` instance for which to retrieve test data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/ImageBasedLightingAssetTester` | A `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/ImageBasedLightingAssetTester` instance used to inspect and manipulate the test data. |

### createTester

```
inline fun <T : Any> createTester(component: Component): T
```

Creates a specific test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component`.

In the test environment, components have corresponding underlying fake data. This function provides a convenient, type-safe way to access the specific tester associated with a component's subclass, allowing for verification or manipulation in tests.

Example usage:

```kotlin
val componentTester = rule.createTester<BoundsComponentTester>(myBoundsComponent)
```

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | The expected type of the component tester (e.g., `BoundsComponentTester`). |
| `component: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component` instance for which to retrieve the test data accessor. |

| Returns |
|---|---|
| `T` | A tester instance of type `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Component)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the underlying tester created for the component does not match the expected type `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Component)`, or if no tester is found. |

### createTester

```
inline fun <T : Any> createTester(entity: Entity): T
```

Creates a specific test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

In the test environment, entities have corresponding underlying fake data. This function provides a convenient, type-safe way to access the specific tester associated with an entity's subclass, allowing for verification or manipulation in tests.

Example usage:

```kotlin
val entityTester = rule.createTester<PanelEntityTester>(myPanelEntity)
```

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | The expected type of the entity tester (e.g., `PanelEntityTester`). |
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` instance for which to retrieve the test data accessor. |

| Returns |
|---|---|
| `T` | A tester instance of type `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Entity)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the underlying tester created for the entity does not match the expected type `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SceneCoreTestRule#createTester(androidx.xr.scenecore.Entity)`. |

### createTester

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

```
fun createTester(gltfModel: GltfModel): GltfModelTester
```

Retrieves a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModel`.

In the test environment, each model created via `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModel.Companion#create(androidx.xr.scenecore.runtime.RenderingRuntime,kotlin.String)` has corresponding underlying fake data. This function provides access to that fake data, allowing for verification or manipulation in tests.

| Parameters |
|---|---|
| `gltfModel: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModel` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModel` instance for which to retrieve test data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/GltfModelTester` | A `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/GltfModelTester` instance used to inspect and manipulate the test data. |

### createTester

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

```
fun createTester(mediaPlayer: MediaPlayer): SpatialMediaPlayerTester
```

Creates the test data accessor for the given `https://developer.android.com/reference/android/media/MediaPlayer.html`.

This class provides a mechanism for tests to inspect and verify spatial audio attributes associated with a `https://developer.android.com/reference/android/media/MediaPlayer.html` that are otherwise encapsulated within the SceneCore runtime.

| Parameters |
|---|---|
| `mediaPlayer: https://developer.android.com/reference/android/media/MediaPlayer.html` | The `https://developer.android.com/reference/android/media/MediaPlayer.html` audio attributes are associated with. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialMediaPlayerTester` | A `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialMediaPlayerTester` instance used to inspect and manipulate the test data. |

### createTester

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

```
fun createTester(soundEffectPool: SoundEffectPool): SoundEffectPoolTester
```

Retrieves a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool`.

In the test environment, each `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` created via `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.Companion#create(androidx.xr.scenecore.runtime.SceneRuntime,kotlin.Int)` has corresponding underlying fake data. This function provides access to that fake data, allowing for verification or manipulation in tests.

| Parameters |
|---|---|
| `soundEffectPool: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` instance for which to retrieve test data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SoundEffectPoolTester` | A `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SoundEffectPoolTester` instance used to inspect and manipulate the test data. |

### createTester

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

```
fun createTester(texture: Texture): TextureTester
```

Creates a test data accessor for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`.

In the test environment, each texture created via `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture#create(androidx.xr.runtime.Session,java.nio.file.Path)` has corresponding underlying fake data. This function provides access to that fake data, allowing for verification or manipulation in tests.

| Parameters |
|---|---|
| `texture: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` instance for which to retrieve test data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/TextureTester` | A `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/TextureTester` instance used to inspect and manipulate the test data. |

## Protected functions

### after

```
protected open fun after(): Unit
```

### before

```
protected open fun before(): Unit
```

## Public properties

### activitySpaceTester

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

```
val activitySpaceTester: ActivitySpaceTester
```

Provides the instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/ActivitySpaceTester` which is a test data accessor of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`.

The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace` is an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` used to track the system-managed pose and boundary of the volume associated with a spatialized Activity. The Application cannot directly control this volume, but the system might update it in response to the User moving it or entering or exiting Full Space Mode.

### mainPanelEntityTester

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

```
val mainPanelEntityTester: MainPanelEntityTester
```

Provides the test-only accessor for `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MainPanelEntity` that enables direct manipulation and inspection of its internal state.

### perceptionSpaceTester

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

```
val perceptionSpaceTester: PerceptionSpaceTester
```

Provides the instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/PerceptionSpaceTester` which is a test data accessor of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PerceptionSpace`.

The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PerceptionSpace` represents the origin of the space in which ARCore for Jetpack XR provides tracking info. The transformations provided by the PerceptionSpace are only valid for the call frame, as the transformation can be changed by the system at any time.

### sceneTester

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

```
val sceneTester: SceneTester
```

Provides access to a controller for simulating runtime spatial states of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Scene`.

Use this to test how your application responds to changes in various spatial-related runtime states, such as visibility, capability and so on.

### spatialAudioTrackBuilderTester

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

```
val spatialAudioTrackBuilderTester: SpatialAudioTrackBuilderTester
```

Provides the test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialAudioTrackBuilder`.

This class provides a mechanism for tests to inspect and verify spatial audio attributes associated with an `https://developer.android.com/reference/android/media/AudioTrack.Builder.html` that are otherwise encapsulated within the SceneCore runtime.

### spatialAudioTrackTester

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

```
val spatialAudioTrackTester: SpatialAudioTrackTester
```

Provides the test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialAudioTrack`.

This class provides a mechanism for tests to inspect and verify spatial audio attributes associated with an `https://developer.android.com/reference/android/media/AudioTrack.html` that are otherwise encapsulated within the SceneCore runtime.

### spatialEnvironmentTester

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

```
val spatialEnvironmentTester: SpatialEnvironmentTester
```

The test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialEnvironment`.

### spatialSoundPoolTester

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

```
val spatialSoundPoolTester: SpatialSoundPoolTester
```

This provides a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialSoundPoolTester` instance for accessing the SpatialSoundPool's underlying fake test data.

### spatialWindowTester

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

```
val spatialWindowTester: SpatialWindowTester
```

Provides the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/testing/SpatialWindowTester` test data accessor for the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialWindow`.