https://kotlinlang.org logo
#mockk
Title
# mockk
h

huehnerlady

01/13/2021, 4:59 PM
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

christophsturm

01/13/2021, 5:07 PM
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

Mattia Tommasone

01/13/2021, 8:11 PM
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

huehnerlady

01/14/2021, 7:08 AM
@Mattia Tommasone I do not know the implementation of the spock way, but I would guess that both are stubbed then 🤔
30 Views