package com.elpassion.android.commons.espresso

import android.app.Instrumentation
import android.content.Intent
import android.os.Bundle
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.widget.TextView
import org.junit.Rule
import org.junit.Test

class ActivityTestRuleUtilsTest {

    @JvmField @Rule
    val activityRule = ActivityTestRule(Activity::class.java, false, false)

    @Test(expected = RuntimeException::class)
    fun shouldFailWhenActivityNotStarted() {
        onText("text").doesNotExist()
    }

    @Test
    fun shouldStartActivity() {
        activityRule.startActivity()
        onText("text").doesNotExist()
    }

    @Test
    fun shouldStartActivityWithIntent() {
        activityRule.startActivity(Intent().apply { putExtra("TEXT_KEY", "text") })
        onText("text").isDisplayed()
    }

    class Activity : android.app.Activity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(TextView(this).apply {
                text = intent.getStringExtra("TEXT_KEY")
            })
        }
    }
}
package com.elpassion.android.commons.espresso

import android.app.Instrumentation
import android.content.Intent
import android.os.Bundle
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.widget.TextView
import org.junit.Assert.assertNull
import org.junit.Rule
import org.junit.Test

class ActivityTestRuleUtilsTest {

    @JvmField @Rule
    val activityRule = ActivityTestRule(Activity::class.java, false, false)

    @Test
    fun shouldNotStartActivity() {
        assertNull(activityRule.activity)
    }

    @Test
    fun shouldStartActivity() {
        activityRule.startActivity()
        onText("text").doesNotExist()
    }

    @Test
    fun shouldStartActivityWithIntent() {
        activityRule.startActivity(Intent().apply { putExtra("TEXT_KEY", "text") })
        onText("text").isDisplayed()
    }

    class Activity : android.app.Activity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(TextView(this).apply {
                text = intent.getStringExtra("TEXT_KEY")
            })
        }
    }
}
Change test to improve test performance
Change test to improve test performance

elpassion/android-commons,elpassion/android-commons,elpassion/android-commons