Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kotlin functions providing ActivityTestRule and IntentsTestRule with a simplified syntax.
import android.app.Activity
import android.support.test.espresso.intent.rule.IntentsTestRule
import android.support.test.rule.ActivityTestRule
inline fun <reified T : Activity> activityTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) =
ActivityTestRule(T::class.java, initialTouchMode, launchActivity)
inline fun <reified T : Activity> intentsTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) =
IntentsTestRule(T::class.java, initialTouchMode, launchActivity)
@sczerwinski

This comment has been minimized.

Owner

sczerwinski commented Jun 3, 2017

Example usage:

@RunWith(AndroidJUnit4::class)
class MyTestClass {

	@Rule
	@JvmField
	val activityRule = activityTestRule<MainActivity>()

	@Rule
	@JvmField
	val intentsRule = intentsTestRule<MainActivity>(launchActivity = false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment