I have a function say
Myfunction() {
x.RunAsync() //Async Function call
}
I have to write a test case for Myfunction()
. I am using go-mock for this. Also have mocked x
.
Test_MyFunction() {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
//EXPECT() call to stub RunAsync()
}
Problem now is my test runs successfully, but somehow at the end it panics saying, that call to mockX.RunAsync()
is missing.
I think this is because defer is being executed before my RunAsync was stubbed.
How do I ensure that all Async functions run before defer is executed.