---
title: "SubspaceTestContext"
description: "Provides the testing context used for retrieving and interacting with 3D Semantics nodes present within a Subspace spatial compose hierarchy."
type: "class"
lastmod: "2026-06-18T10:32:52.446446Z"
---
## API Reference

> Source set: Android

```kotlin
public class SubspaceTestContext
internal constructor(private val testRule: AndroidComposeTestRule<*, *>)
```

Provides the testing context used for retrieving and interacting with 3D Semantics nodes present
within a Subspace spatial compose hierarchy.

This context wraps an `AndroidComposeTestRule` and allows [SubspaceSemanticsNodeInteraction](/jetpack-compose/androidx.xr.compose/compose-testing/classes/SubspaceSemanticsNodeInteraction) to
extract spatial layout semantics, perform layout assertions, and filter specific elements in XR
environments.

## Code Examples

### subspaceNodeMatcherProperties
```kotlin
public fun subspaceNodeMatcherProperties() {
    composeTestRule.setContent {
        Subspace {
            SpatialPanel(SubspaceModifier.width(100.dp).height(100.dp).testTag("myPanel")) {}
        }
    }
    // Check existence and exact spatial dimensions in DP using semantic matchers
    composeTestRule
        .onSubspaceNodeWithTag("myPanel")
        .assertExists()
        .assertPositionInRootIsEqualTo(0.dp, 0.dp, 0.dp)
        .assertWidthIsEqualTo(100.toDp())
        .assertHeightIsEqualTo(100.toDp())
}
```

### subspacePanelRenderedAndInteractive
```kotlin
public fun subspacePanelRenderedAndInteractive() {
    var count = 0
    composeTestRule.setContent {
        Subspace {
            SpatialPanel(SubspaceModifier.testTag("spatialPanel")) {
                Button(onClick = { count++ }) { Text("Increment") }
            }
        }
    }
    // Assert subspace node existence, position, and dimensions in the Spatial hierarchy
    composeTestRule
        .onSubspaceNodeWithTag("spatialPanel")
        .assertExists()
        .assertPositionInRootIsEqualTo(0.toDp(), 0.toDp(), 0.toDp())
    // Interact with the 2D Compose node nested within the Spatial container
    composeTestRule.onNodeWithText("Increment").performClick()
    composeTestRule.waitForIdle()
    // Verify outcomes
    assert(count == 1)
}
```
