stojan
val testContext: Context = ApplicationProvider.getApplicationContext() val testCoroutineDispatcher = StandardTestDispatcher() val testCoroutineScope = TestScope(testCoroutineDispatcher + Job()) val testDataStore: DataStore<Preferences> = PreferenceDataStoreFactory.create( scope = testCoroutineScope, produceFile = { testContext.preferencesDataStoreFile("test_datastore") } )
testCoroutineScope.runTest {}
@After
runBlocking {}
runBlocking(testCoroutineDispatcher) {}
Sam
fun TestScope.runTestAndCleanup(body: TestScope.() -> Unit) = runTest { try { body() } finally { cleanup() } }
A modern programming language that makes developers happier.