Hi, Does anyone know how I can use mockk to say “...
# mockk
h
Hi, Does anyone know how I can use mockk to say “this methos with any parameters”? In spock you have the operator
*_
for that (see here) Example
fun foo(p1: String, p2: Boolean, p3: Int): Boolean
I want to write something like this in a test:
every {foo(anyParameters())} returns true
Currently the only way I know is:
every {foo(any(), any(), any())} returns true
Is there a way to be less verbose and just say
anything
? I tried
allAny()
as that sounded like what I wanted, but that didn’t help me either, for me it feels like this is the same as
any()
?
c
i think what you want is not possible because kotlin is strictly typed
in the every block you just call the method that you want to mock and for that call to be valid you need to pass 3 parameters
m
that is correct suppose your
foo
method has two implementations, one taking two parameters and one taking three which one would you be stubbing if you had
anyParameters()
?
h
@Mattia Tommasone I do not know the implementation of the spock way, but I would guess that both are stubbed then 🤔