Created
August 23, 2020 17:13
-
-
Save Audhil/caeac044766d2f1793a09e750bb6451f to your computer and use it in GitHub Desktop.
instrumentation tests - actual test cases
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 characters
@UninstallModules(APIModule::class, OtherModule::class) | |
@HiltAndroidTest | |
class MainActivityTest { | |
@get:Rule | |
var hiltRule = HiltAndroidRule(this) | |
@Rule | |
@JvmField | |
val activityRule = ActivityTestRule(MainActivity::class.java, true, false) | |
private lateinit var mockServer: MockWebServer | |
@Before | |
fun setUp() { | |
mockServer = MockWebServer() | |
mockServer.start(8080) | |
} | |
@After | |
fun tearDown() = | |
mockServer.shutdown() | |
@Test | |
fun happyTestCase() { | |
mockServer.dispatcher = object : Dispatcher() { | |
override fun dispatch(request: RecordedRequest): MockResponse { | |
return MockResponse() | |
.setResponseCode(200) | |
.setBody(FileReader.readStringFromFile("success_response.json")) | |
} | |
} | |
activityRule.launchActivity(null) | |
Espresso.onView(withId(R.id.progress_bar)).run { | |
check(ViewAssertions.matches(not(ViewMatchers.isDisplayed()))) | |
} | |
Espresso.onView(withId(R.id.repo_recycler_view)).run { | |
check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | |
} | |
} | |
@Test | |
fun unHappyTestCase() { | |
mockServer.dispatcher = object : Dispatcher() { | |
override fun dispatch(request: RecordedRequest): MockResponse { | |
return MockResponse().throttleBody(1024, 5, TimeUnit.SECONDS) | |
} | |
} | |
activityRule.launchActivity(null) | |
Espresso.onView(withId(R.id.retry_btn)).run { | |
check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment