android6-3 Exercise 3: Testing the worker ====================================== // app/src/androidTest/.../SyncNotesWorkerTest.kt @RunWith(AndroidJUnit4::class) class SyncNotesWorkerTest { @Test fun syncSucceeds() = runTest { val context = ApplicationProvider.getApplicationContext() val worker = TestListenableWorkerBuilder(context).build() val result = worker.doWork() assertEquals(ListenableWorker.Result.success(), result) } } Second test: build the worker the same way, with a fake repository returning RefreshResult.NoConnection, and assert the result equals ListenableWorker.Result.retry(). Problem: SyncNotesWorker reaches its repository through (applicationContext as NotesApplication).container, so the test cannot swap it. Options (general knowledge): let the test application provide a container with fakes; give the worker a small factory (a WorkerFactory) that supplies the repository, which is what the Hilt pattern in the chapter does through HiltWorkerFactory. Report which you chose. Code unrun.