AndroidComposeExtension

class AndroidComposeExtension<A : ComponentActivity> : ComposeExtension, BeforeEachCallback, BeforeTestExecutionCallback, AfterTestExecutionCallback, AfterEachCallback, ParameterResolver

A JUnit 5 Extension that allows you to test and control Composables and application using Compose. The functionality of testing Compose is provided by means of the runComposeTest method, which receives a ComposeContext from which the test can be orchestrated. The test will block until the app or composable is idle, to ensure the tests are deterministic.

This extension can be added to any JUnit 5 class using the ExtendWith annotation, or registered globally through a configuration file. Alternatively, you can instantiate the extension in a field within the test class using any of the createComposeExtension or createAndroidComposeExtension factory methods.

Properties

Link copied to clipboard
val activity: A
Link copied to clipboard

Functions

Link copied to clipboard
open override fun afterEach(context: ExtensionContext)
Link copied to clipboard
open override fun afterTestExecution(context: ExtensionContext)
Link copied to clipboard
open override fun beforeEach(context: ExtensionContext)
Link copied to clipboard
open override fun beforeTestExecution(context: ExtensionContext)
@API(status = API.Status.EXPERIMENTAL, since = "5.12")
open fun getTestInstantiationExtensionContextScope(rootContext: ExtensionContext): TestInstantiationAwareExtension.ExtensionContextScope
Link copied to clipboard
open override fun resolveParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Any
Link copied to clipboard
open fun runComposeTest(block: ComposeContext.() -> Unit)
Link copied to clipboard
open override fun supportsParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Boolean
Link copied to clipboard
open override fun use(block: ComposeContext.() -> Unit)

Set up and drive the execution of a Compose test within the provided block. Depending on the time this is called, it will either queue up a preparatory action for the test (e.g. in @BeforeEach) The receive of this block is a ComposeContext, through which you can access all sorts of utilities to drive the execution of the test, such as driving the clock or executing actions on the UI thread. The main purpose is provided through ComposeContext.setContent, however: With this function, you can pass an arbitrary composable tree to the extension and evaluate it afterwards.