fun foo(callback){
GlobalScope.launch {
val x = async {//}.await()
callback(x)
}
}
//Test
@Test
`test that we can test`(){
//i should be able to test that callback is called with value x
}
e
E.Kisaragi
01/27/2020, 2:58 AM
make callback type (T) -> Unit where T is your type, and it can take println in the test
e
Erik
01/27/2020, 8:44 AM
In general prefer not to use GlobalScope, but instead make the scope a dependency so you can test using e.g. TestCoroutineScope. But to verify that the callback was invoked, just pass a test callback that sets some asserted value. If this question is #C1CFAFJSK specific, then better ask there! #CGN6QTTFE is also an option.
👍 1
p
paulex
01/27/2020, 10:02 AM
@Erik Yeah, i'm passing a test callback, that is a mock of the callback that i can test...
Copy code
val callback = mockk<StreamObserver<Wallet>>()
val slot = slot<Wallet>()
every { callback.onNext(capture(slot)) } just Runs
every { callback.onCompleted() } just Runs
paulex
01/27/2020, 10:03 AM
i can ascertain within the
foo
function that the code within launch block runs..
However it seems that my test function runs to completion before the callback..
paulex
01/27/2020, 10:55 AM
@Erik Thanks, it works now... so i had to inject the scope like you said...