Nice and simple DSL for Espresso Compose in Kotlin
- Readability
- Reusability
- Extensible DSL
Create your entity ComposeScreen
where you will add the views involved in the interactions of the tests:
class MainActivityScreen(composeTestRule: AndroidComposeTestRule<*, *>):
ComposeScreen<MainActivityScreen>(composeTestRule)
ComposeScreen
can represent the whole user interface or a portion of UI.
If you are using Page Object pattern you can put the interactions of Kakao inside the Page Objects.
ComposeScreen
contains KNode
, these are the Android Framework views where you want to do the interactions:
class MainActivityScreen(composeTestRule: AndroidComposeTestRule<*, *>) :
ComposeScreen<MainActivityScreen>(composeTestRule) {
val myButton = KNode(this) {
hasTestTag("myTestButton")
}
}
Every KNode
contains many matches. Some examples of matchers provided by Kakao Compose:
hasText
hasTestTag
- and more
Like in Espresso you can combine different matchers:
val myButton = KNode(this) {
hasTestTag("myTestButton")
hasText("Button 1")
}
The syntax of the test with Kakao is very easy, once you have the ComposeScreen
and the KNode
defined, you only have to apply
the actions or assertions like in Espresso:
class ExampleInstrumentedTest {
@Rule
@JvmField
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Test
fun simpleTest() {
onComposeScreen<MainActivityScreen>(composeTestRule) {
myButton {
assertIsDisplayed()
assertTextContains("Button 1")
}
onNode {
hasTestTag("doesNotExist")
}.invoke {
assertDoesNotExist()
}
}
}
}
Maven
<dependency>
<groupId>io.github.kakaocup</groupId>
<artifactId>compose</artifactId>
<version><latest version></version>
<type>pom</type>
</dependency>
or Gradle:
dependencies {
androidTestImplementation 'io.github.kakaocup:compose:<latest version>'
}
Kakao Compose is an open source project, and depends on its users to improve it. We are more than happy to find you interested in taking the project forward.
Kindly refer to the Contribution Guidelines for detailed information.
Please refer to Code of Conduct document.
Kakao Compose is open source and available under the Apache License, Version 2.0.