Last Updated: February 25, 2016
· kinjacono

Mockito argument matchers and Scala

Attempting to use Mockito argument matchers in your Scala tests and getting a frustrating

Invalid use of argument matchers!

for no obvious reason?

Check that the function you're matching arguments on doesn't have any default values! All arguments need to be matchers, even if the values are provided by defaults:

def doCoolStuff(thing: Thing, message: String = "") = { ... }

Then the following will throw an InvalidUseOfMatchersException:


But using a matcher for the defaulted parameters will work: