-
- All Implemented Interfaces:
-
de.mannodermaus.junit5.compose.ComposeExtension,org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.AfterTestExecutionCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.BeforeTestExecutionCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver
public final class AndroidComposeExtension<A extends ComponentActivity> implements 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.
-
-
Field Summary
Fields Modifier and Type Field Description private final ActivityScenario<A>scenarioprivate final Aactivity
-
Method Summary
Modifier and Type Method Description final ActivityScenario<A>getScenario()final AgetActivity()Unituse(Function1<ComposeContext, Unit> block)Set up and drive the execution of a Compose test within the provided block. UnitbeforeEach(ExtensionContext context)UnitbeforeTestExecution(ExtensionContext context)UnitafterTestExecution(ExtensionContext context)UnitafterEach(ExtensionContext context)BooleansupportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)ObjectresolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)-
-
Method Detail
-
getScenario
final ActivityScenario<A> getScenario()
-
getActivity
final A getActivity()
-
use
Unit use(Function1<ComposeContext, Unit> block)
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.
-
beforeEach
Unit beforeEach(ExtensionContext context)
-
beforeTestExecution
Unit beforeTestExecution(ExtensionContext context)
-
afterTestExecution
Unit afterTestExecution(ExtensionContext context)
-
supportsParameter
Boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
-
resolveParameter
Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
-
-
-
-