Last active
February 22, 2020 13:12
-
-
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.
This file contains hidden or 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
/** | |
* 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