SessionTestRule


public final class SessionTestRule extends 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

Public methods

final SessionConfigureResult

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

final SessionCreateResult

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

final void

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

final void

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

Protected methods

void
void

Inherited methods

From org.junit.rules.TestRule

Public constructors

SessionTestRule

Added in 1.0.0-beta01
public SessionTestRule()

Public methods

getConfigureResult

Added in 1.0.0-beta01
public final SessionConfigureResult getConfigureResult()

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.

getCreateResult

Added in 1.0.0-beta01
public final SessionCreateResult getCreateResult()

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.

setConfigureResult

Added in 1.0.0-beta01
public final void setConfigureResult(SessionConfigureResult value)

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.

setCreateResult

Added in 1.0.0-beta01
public final void setCreateResult(SessionCreateResult value)

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.

Protected methods

after

protected void after()

before

Added in 1.0.0-beta01
protected void before()