Skip to content

Instantly share code, notes, and snippets.

@samuel22gj
Last active February 22, 2020 13:12
Show Gist options
  • Save samuel22gj/f331231a6c1c57df409bf229fb154c2d to your computer and use it in GitHub Desktop.
Save samuel22gj/f331231a6c1c57df409bf229fb154c2d to your computer and use it in GitHub Desktop.
Rule to be used in tests that display a Toast with class name and method name when each test starting.
/**
* Rule to be used in tests that display a Toast with class name and method name when each test starting.
*
* ```
* @RunWith(AndroidJUnit4::class)
* class FooTest {
*
* @get:Rule
* val testNameToastRule = TestNameToastRule()
*
* @Test
* fun testBar() {
* ....
* }
* }
* ```
*/
class TestNameToastRule : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
Handler(Looper.getMainLooper()).post {
Toast.makeText(
ApplicationProvider.getApplicationContext(),
"${description?.testClass?.simpleName}.${description?.methodName}",
Toast.LENGTH_LONG
).show()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment