Skip to content

Instantly share code, notes, and snippets.

@tugceaktepe
Last active June 15, 2023 20:13
Show Gist options
  • Save tugceaktepe/2d91e44ac90fd77502c587fa750a70d6 to your computer and use it in GitHub Desktop.
Save tugceaktepe/2d91e44ac90fd77502c587fa750a70d6 to your computer and use it in GitHub Desktop.
Adding mockWebServer for the first time.
@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(){
val scenario = launchActivity<MainActivity>()
onView(withId(R.id.recyclerViewMovies))
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
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