Skip to content

Instantly share code, notes, and snippets.

@tugceaktepe
Created June 15, 2023 21:45
Show Gist options
  • Save tugceaktepe/432e4238989ff74e950d329e7cb2fc22 to your computer and use it in GitHub Desktop.
Save tugceaktepe/432e4238989ff74e950d329e7cb2fc22 to your computer and use it in GitHub Desktop.
Add success test
@UninstallModules(
UrlModule::class
)
@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)
private val mockWebServer = MockWebServer()
@Before
fun setUp(){
IdlingRegistry.getInstance().register(TestIdlingResource.countingIdlingResource)
mockWebServer.start(8080)
}
@Test
fun screenIsReady(){
mockWebServer.dispatcher = MockServerDispatcher().RequestDispatcher()
val scenario = launchActivity<MainActivity>()
onView(withId(R.id.recyclerViewMovies)).check { view, noViewFoundException ->
if (noViewFoundException != null) {
throw noViewFoundException
}
val recyclerView = view as RecyclerView
assertEquals(21, recyclerView.adapter?.itemCount)
}
scenario.close()
}
@After
fun tearDown(){
mockWebServer.shutdown()
IdlingRegistry.getInstance().unregister(TestIdlingResource.countingIdlingResource)
}
@Module
@InstallIn(SingletonComponent::class)
class FakeBaseUrlModule {
@Provides
@Singleton
fun provideUrl() : String = "http://127.0.0.1:8080"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment