curioustechizen
02/02/2024, 9:43 AMMockEngine
to test a POST request?
I'm following the example here (except I'm using testScope.runTest
to execute the test). However it looks like my request is never executed. If I inspect mockEngine.requestHistory
immediately after performing the POST I see it is empty.Aleksei Tirman [JB]
02/02/2024, 10:08 AMcurioustechizen
02/02/2024, 10:10 AMcurioustechizen
02/02/2024, 10:13 AMapplicationScope.launch { <http://httpClient.post|httpClient.post>() }
Where applicationScope
is a separate CoroutineScope that I inject into the class under test. The objective of this is to continue executing the HTTP request even if the calling scope is cancelled (for example even if the user moves away to a different screen)
But I'm also executing the test inside a TestScope
provided by kotlin coroutines test library. So looks like both of them are in the same scope and that ends in the parent scope being cancelled.curioustechizen
02/02/2024, 10:13 AMapplicationScope.launch
part and directly run my http request in the scope of the calling function, I see some Ktor logs so at least the request is happening.