Skip to content

Instantly share code, notes, and snippets.

@AjeshRPai
Last active January 30, 2018 09:50
Show Gist options
  • Save AjeshRPai/8cf80f51fb944ffd20b1d2ae859436ef to your computer and use it in GitHub Desktop.
Save AjeshRPai/8cf80f51fb944ffd20b1d2ae859436ef to your computer and use it in GitHub Desktop.

Revisions

  1. AjeshRPai revised this gist Jan 30, 2018. 1 changed file with 1 addition and 42 deletions.
    43 changes: 1 addition & 42 deletions MainActivityInstrumentation
    Original 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 is initialized
    @Rule
    @JvmField
    public val rule = getRule()

    public val rule = ActivityTestRule(MainActivity::class.java)

    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")
    @@ -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)))

    }

    @After
    fun after_test_method() {
    Log.e("@After", "Hi this is run after every test function")
    }

    }
  2. AjeshRPai created this gist Jan 30, 2018.
    92 changes: 92 additions & 0 deletions MainActivityInstrumentation
    Original 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")
    }

    }