Mockito, testing, nulls and exceptions

Personally, I think Mockito has no business being in a Scala codebase – it is too type-weak and null-happy. Scalamock is a little better, but still leads to too many nulls. Java code tends to be cautious about null, because they are common there, but Scala code assumes there aren’t any nulls floating around, so it tends to just crash.

I have a vague ambition (and I’d encourage somebody else to pick up the ball and run with it before I get to it) to fork Scalamock to change one aspect: when you hit an undefined method, immediately throw an Exception, instead of silently injecting a null that will cause confusing errors later. While that wouldn’t be perfect, I suspect it would work better in practice…

3 Likes