Last active
January 30, 2018 09:50
-
-
Save AjeshRPai/8cf80f51fb944ffd20b1d2ae859436ef to your computer and use it in GitHub Desktop.
Revisions
-
AjeshRPai revised this gist
Jan 30, 2018 . 1 changed file with 1 addition and 42 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,46 +9,14 @@ 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") @@ -63,8 +31,6 @@ class MainActivityInstrumentationTest { Espresso.onView(withId(R.id.login_result)) .check(matches(withText(R.string.login_success))) } @Test @@ -81,12 +47,5 @@ class MainActivityInstrumentationTest { Espresso.onView(withId(R.id.login_result)) .check(matches(withText(R.string.login_failed))) } } -
AjeshRPai created this gist
Jan 30, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,92 @@ 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 is initialized @Rule @JvmField public val rule = getRule() private val username_tobe_typed="Ajesh" private val correct_password ="password" private val wrong_password = "passme123" private fun getRule(): ActivityTestRule<MainActivity> { Log.e("Initalising rule","getting Mainactivity") return ActivityTestRule(MainActivity::class.java) } companion object { @BeforeClass @JvmStatic fun before_class_method(){ Log.e("@Before Class","Hi this is run before anything") } @AfterClass @JvmStatic fun after_class_method(){ Log.e("@After Class","Hi this is run after everything") } } @Before fun before_test_method(){ Log.e("@Before","Hi this is run before every test function") } @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))) } @After fun after_test_method() { Log.e("@After", "Hi this is run after every test function") } }