Add BaseComposeTest for facilitating compose-layer testing (#14)

This commit is contained in:
Brian Yencho 2023-08-29 13:07:55 -05:00 committed by Álison Fernandes
parent b337fbfd20
commit 17d5475d0f
2 changed files with 25 additions and 16 deletions

View file

@ -1,30 +1,17 @@
package com.x8bit.bitwarden.example package com.x8bit.bitwarden.example
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performClick
import dagger.hilt.android.testing.HiltTestApplication import com.x8bit.bitwarden.example.ui.BaseComposeTest
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
/** /**
* Example showing that Compose tests using "junit" imports and Roboelectric work. * Example showing that Compose tests using "junit" imports and Robolectric work.
*/ */
@Config( class ExampleComposeTest : BaseComposeTest() {
application = HiltTestApplication::class,
sdk = [Config.NEWEST_SDK],
)
@RunWith(RobolectricTestRunner::class)
class ExampleComposeTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test @Test
fun `the onClick callback should be correctly triggered when performing a click`() { fun `the onClick callback should be correctly triggered when performing a click`() {
var isClicked = false var isClicked = false

View file

@ -0,0 +1,22 @@
package com.x8bit.bitwarden.example.ui
import androidx.compose.ui.test.junit4.createComposeRule
import dagger.hilt.android.testing.HiltTestApplication
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
/**
* A base class that can be used for performing Compose-layer testing using Robolectric, Compose
* Testing, and JUnit 4.
*/
@Config(
application = HiltTestApplication::class,
sdk = [Config.NEWEST_SDK],
)
@RunWith(RobolectricTestRunner::class)
abstract class BaseComposeTest {
@get:Rule
val composeTestRule = createComposeRule()
}