Category : integration-testing

I’m trying to run an end-to-end espresso test. The flow involves updating the picture of the user: the user fetches a picture from the gallery, crops the image using an external library (UCrop) and then sends the cropped image to the backend. Problem in the test flow is that I run the test, and I ..

Read more

This is my testing class: class RocketListVMTest { @get:Rule var instantTaskExecutorRule = InstantTaskExecutorRule() private lateinit var sut: RocketListVM private var activeOnlyToggle = false private val repo: Repo = mock() @Before fun setUp() { sut = RocketListVM(repo) activeOnlyToggle = false } @Test fun toggleActiveOnlyWithTrueCallsRepository() { sut.toggleActiveOnly(true) verify(repo).getActiveOnlyLocalRockets() } } With the following dependencies: androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" androidTestImplementation ..

Read more

In my integration test, I enqueue a worker that has constraints battery, .setRequiresBatteryNotLow(true) meaning the worker will not doWork() until the constraints are met. Normally, in a unit test one could capture the id of the enqueued worker and use the testDriver to trick the test that all constraints have been met using: testDriver.setAllConstraintsMet(request.id) I ..

Read more

My ViewModel has a method which returns a flow of PagingData: fun getChocolates(): Flow<PagingData<Chocolate>> { … … } How do I test this method? What I’ve tried so far: @InternalCoroutinesApi @Test fun getChocolateListReturnsCorrectData() = runBlockingTest { val dao: Dao by inject() val viewModel: ViewModel by inject() // 1 val chocolate1 = Chocolate( name = "Dove" ..

Read more

I try to mock my retrofit calls with MockWebServer in the instrumentation tests. For some reason I can’t even initialise my MockWebServer instance and get the following exception: E/TestRunner: java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/concurrent/TaskRunner$RealBackend; This is my test code: class HttpAdapterAndroidTest { private val testContext = InstrumentationRegistry.getInstrumentation().context private val mockWebServer: MockWebServer = MockWebServer() .apply { ..

Read more

So, I have a navigation drawer and I want to test that it is closing when item is selected. Here is my test: @Test fun `choosing any menu item from navigation drawer should close it`(){ mainScenario.onActivity { // open drawer val v: View = it.findViewById(android.R.id.content) val drawer = v.rootView.findViewById<DrawerLayout>(R.id.drawer_layout) // when closing drawer animation should ..

Read more