Testing play framework controller witch uses custom action #11456
Replies: 1 comment
-
This isn't meant to be at all snarky, but "using mockito" is my gut response. It's a very brittle tool to begin with, and has incredibly sharp edges when applied to Scala. It's extremely weakly-typed and null-prone, so this sort of error happens all the time. (When I started at a previous job, I lost literally months just fixing this sort of Mockito error -- it was pretty miserable.) If you must do mocking, I recommend the somewhat-more-robust ScalaMock instead. But in general, my rule of thumb is to work quite differently. If you're interested in exploring a different way of operating, I have a series of articles that outlines the testing approach that I've found works best for serious Scala services, based on 10 years of doing so. |
Beta Was this translation helpful? Give feedback.
-
I want to unit-test a controller method and to do that I need to mock out every dependency.
This is my controller:
I made a custom action with ActionBuilder and it is injected in the constructor. I use this action to Authenticate users.
I want to mock this out completely.
My unit test looks like this:
After running the test I get NullPointerException.
I'm using mockito and scala test plus.
What am I missing or doing wrong?
If you know a better way to test this, please help.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions