Created
June 15, 2023 21:45
-
-
Save tugceaktepe/432e4238989ff74e950d329e7cb2fc22 to your computer and use it in GitHub Desktop.
Add success test
This file contains 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( | |
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