Kulwinder Singh
03/09/2020, 7:58 AMFirebaseAuth.getInstance().signInWithCustomToken(token).addOnCompleteListener{}
and other Task like addOnSuccessListener
and addOnFailureListener
using MockK ?Samme Kleijn
03/09/2020, 8:09 AM@MockK(relaxed = true)
private lateinit var mockTask: Task<List<FirebaseVisionBarcode>>
every { mockTask.addOnFailureListener(any()) } answers {
firstArg<OnFailureListener>().onFailure(mockk())
mockTask
}
To mock invoke a failureMatej Drobnič
03/09/2020, 8:15 AMTasks.forException(...)
Kulwinder Singh
03/09/2020, 8:21 AMFirebaseAuth.getInstance().signInWithCustomToken(token).addOnCompleteListener
i have created
lateinit var mockAuthTask: Task<AuthResult>
...
beforeEachTest{
.....
every { mockAuthTask.addOnSuccessListener(any()) } answers { firstArg<OnCompleteListener<AuthResult>>().onComplete(mockk()) }
}
Matej Drobnič
03/09/2020, 8:38 AMval result = AuthResult(...)
val authTask = Tasks.forResult(result)
Kulwinder Singh
03/09/2020, 10:06 AMFailure(e=io.mockk.MockKException: no answer found for: Task(#17).getException())
i think i'm getting this because we are sending AuthResult
as mockobject but now i don't know how to solve it 😞Matej Drobnič
03/09/2020, 10:48 AMmockk()
instead of implementing AuthResult I guessFakeAuthResult
class that implements the interfaceKulwinder Singh
03/09/2020, 10:53 AMmock(relaxed=true)
workedMatej Drobnič
03/09/2020, 11:15 AMTasks.forResult(mockk())
is a good compromiseKulwinder Singh
03/09/2020, 11:28 AMno answer found for: SomeClass(#3).setSomeVariable(dummy)
every
for setters of fields ?luke
03/24/2020, 3:21 AM