Created
September 14, 2021 03:27
-
-
Save theapache64/8c5b0330ea4bd8bf72b89527c15206b7 to your computer and use it in GitHub Desktop.
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.material.Button | |
import androidx.compose.material.Text | |
import androidx.compose.ui.test.junit4.createComposeRule | |
import androidx.compose.ui.test.onNodeWithText | |
import androidx.compose.ui.test.performClick | |
import org.junit.Assert | |
import org.junit.Before | |
import org.junit.Rule | |
import org.junit.Test | |
class ExceptionTest { | |
@get:Rule | |
val composeRule = createComposeRule() | |
companion object { | |
private const val ACTION_THROW_ERROR = "THROW ERROR" | |
} | |
@Before | |
fun beforeAll() { | |
composeRule.setContent { | |
Button(onClick = { throw IllegalArgumentException() }) { | |
Text(text = ACTION_THROW_ERROR) | |
} | |
} | |
} | |
@Test(expected = IllegalArgumentException::class) | |
fun throwsError_1() { | |
composeRule.onNodeWithText(ACTION_THROW_ERROR).performClick() | |
} | |
@Test | |
fun throwsError_2() { | |
try { | |
composeRule.onNodeWithText(ACTION_THROW_ERROR).performClick() | |
assert(false) | |
} catch (e: IllegalArgumentException) { | |
assert(true) | |
} | |
} | |
@Test | |
fun throwsError_3() { | |
Assert.assertThrows(IllegalArgumentException::class.java) { | |
composeRule.onNodeWithText(ACTION_THROW_ERROR).performClick() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment