SessionTestRule


class SessionTestRule : ExternalResource


A JUnit TestRule for controlling the results of androidx.xr.runtime.Session operations within tests. This rule intercepts calls to create and configure sessions, allowing tests to inject specific success or failure results.

To use this rule, include it in your test class:

@RunWith(JUnit4::class)
class MySessionTest {
@get:Rule
val sessionTestRule = SessionTestRule()

@Test
fun testSessionCreationFails() = runTest {
sessionTestRule.createResult = SessionCreateResult.Failure(IllegalArgumentException("Test"))
// ... code that calls Session.create() ...
}

@Test
fun testSessionConfigurationSuccess() = runTest {
sessionTestRule.configureResult = SessionConfigureResult.Success
// ... code that calls Session.configure() ...
}
}

Summary

Public constructors

Protected functions

open Unit
open Unit

Public properties

SessionConfigureResult?

The result to be returned when androidx.xr.runtime.Session.configure is called.

SessionCreateResult?

The result to be returned when androidx.xr.runtime.Session.create is called.

Inherited functions

From org.junit.rules.TestRule
open Statement
apply(base: Statement, description: Description)

Public constructors

SessionTestRule

Added in 1.0.0-beta01
SessionTestRule()

Protected functions

after

protected open fun after(): Unit

before

Added in 1.0.0-beta01
protected open fun before(): Unit

Public properties

configureResult

Added in 1.0.0-beta01
var configureResultSessionConfigureResult?

The result to be returned when androidx.xr.runtime.Session.configure is called. If null, the default behavior of the runtime will be used. While this will likely be androidx.xr.runtime.SessionConfigureSuccess, other results are possible, depending on the underlying selected runtime implementation.

createResult

Added in 1.0.0-beta01
var createResultSessionCreateResult?

The result to be returned when androidx.xr.runtime.Session.create is called. If null, the default behavior of the runtime will be used. While this will likely be androidx.xr.runtime.SessionCreateSuccess, other results are possible, depending on the underlying selected runtime implementation.