Created
June 15, 2021 13:15
-
-
Save sonique6784/c6fe26048ea2ea79dc09fa819d7f31df to your computer and use it in GitHub Desktop.
Jetpack Compose: CustomViewTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.ui.test.assertIsDisplayed | |
import androidx.compose.ui.test.junit4.createComposeRule | |
import androidx.compose.ui.test.onNodeWithText | |
import androidx.compose.ui.test.performClick | |
import androidx.test.ext.junit.runners.AndroidJUnit4 | |
import org.junit.Rule | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import kotlin.test.assertTrue | |
//https://developer.android.com/jetpack/compose/testing | |
@RunWith(AndroidJUnit4::class) | |
class CustomViewTest { | |
@get:Rule | |
val composeTestRule = createComposeRule() | |
// createAndroidComposeRule<MainActivity>() if you need access to the activityTestRule | |
// createComposeRule() if you don't need access to the activityTestRule | |
@Test | |
fun MyTest() { | |
// Start the app | |
var isClicked = false | |
composeTestRule.setContent { | |
MyTheme { | |
val data = DataCustomView("my title", "my description") | |
MyCustomView(data, object: MyInterface { | |
override fun onButtonAClicked() { | |
isClicked = true | |
} | |
override fun onButtonBClicked() { | |
TODO("Not yet implemented") | |
} | |
override fun onUserSwipe(coordinate: List<Double>) { | |
TODO("Not yet implemented") | |
} | |
}) | |
} | |
} | |
composeTestRule.onNodeWithText("my title").assertIsDisplayed() | |
composeTestRule.onNodeWithText("my description").assertIsDisplayed() | |
composeTestRule.onNodeWithText("my title").performClick() | |
assertTrue(isClicked, "click was performed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment