Skip to content

Instantly share code, notes, and snippets.

@AjeshRPai
Last active January 30, 2018 09:50
Show Gist options
  • Select an option

  • Save AjeshRPai/8cf80f51fb944ffd20b1d2ae859436ef to your computer and use it in GitHub Desktop.

Select an option

Save AjeshRPai/8cf80f51fb944ffd20b1d2ae859436ef to your computer and use it in GitHub Desktop.
This is the MainActivity Intstrumentation Test Class
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import org.junit.runner.RunWith
import android.support.test.espresso.Espresso;
import android.support.test.espresso.action.ViewActions
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.*
@RunWith(AndroidJUnit4::class)
class MainActivityInstrumentationTest {
@Rule
@JvmField
public val rule = ActivityTestRule(MainActivity::class.java)
private val username_tobe_typed="Ajesh"
private val correct_password ="password"
private val wrong_password = "passme123"
@Test
fun login_success(){
Log.e("@Test","Performing login success test")
Espresso.onView((withId(R.id.user_name)))
.perform(ViewActions.typeText(username_tobe_typed))
Espresso.onView(withId(R.id.password))
.perform(ViewActions.typeText(correct_password))
Espresso.onView(withId(R.id.login_button))
.perform(ViewActions.click())
Espresso.onView(withId(R.id.login_result))
.check(matches(withText(R.string.login_success)))
}
@Test
fun login_failure(){
Log.e("@Test","Performing login failure test")
Espresso.onView((withId(R.id.user_name)))
.perform(ViewActions.typeText(username_tobe_typed))
Espresso.onView(withId(R.id.password))
.perform(ViewActions.typeText(wrong_password))
Espresso.onView(withId(R.id.login_button))
.perform(ViewActions.click())
Espresso.onView(withId(R.id.login_result))
.check(matches(withText(R.string.login_failed)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment