Skip to content

Instantly share code, notes, and snippets.

@Elvis10ten
Last active January 15, 2018 22:37
Show Gist options
  • Save Elvis10ten/631c2e41c10108e3132db61e5f87bb2b to your computer and use it in GitHub Desktop.
Save Elvis10ten/631c2e41c10108e3132db61e5f87bb2b to your computer and use it in GitHub Desktop.
package com.mobymagic.shazamclone.discover
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.filters.LargeTest
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import com.mobymagic.shazamclone.R
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
// Usually UI tests are marked as large tests. Read more on this here: https://testing.googleblog.com/2010/12/test-sizes.html
@LargeTest
class DiscoverFragmentTest {
// Instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field.
@JvmField
// By using ActivityTestRule, the testing framework launches the activity under test before each test method
// annotated with @Test. The framework handles shutting down the activity after the test finishes
@Rule
val mDiscoverActivityTestRule = ActivityTestRule<DiscoverActivity>(DiscoverActivity::class.java)
// Check that clicking the start button opens up the song detail page
@Test
fun clickStartIdentifyButtonOpensSongDetailPage() {
// Click on the start button
onView(withId(R.id.discoverStartIdentifyButton)).perform(click())
// Check that the song detail view is shown afterwards
onView(withId(R.id.songDetailFragmentContainer)).check(matches(isDisplayed()))
}
// Check that clicking the donate button opens the donate page
@Test
fun clickDonateButtonOpensDonatePage() {
// Click on the donate button
onView(withId(R.id.discoverDonateButton)).perform(click())
// Check that the donate view is shown afterwards
onView(withId(R.id.donateFragmentContainer)).check(matches(isDisplayed()))
}
// Check that clicking the history button opens the history page
@Test
fun clickHistoryButtonOpensHistoryPage() {
// Click on the history button
onView(withId(R.id.discoverHistoryButton)).perform(click())
// Check that the history view is shown afterwards
onView(withId(R.id.historyFragmentContainer)).check(matches(isDisplayed()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment