mockito
mockito copied to clipboard
Consider using "smart null" answer by default
Mockito ships with optional Answer RETURNS_SMART_NULLS that is useful to tackle problems with incorrect / missing stubbing. Do you think returning "smart nulls" should be the default behavior of Mockito mocks? Smart null pointer exception is always better than regular NullPointerException when it comes to debugging tests and figuring out why they fail.
The purpose of this ticket is to get feedback and make a decision whether to make returning "smart null" a default behavior in Mockito 3.
+1, I like smart nulls.
Btw, for people wanting to test it right know it was possible to configure it globally for the whole project using MockitoConfiguration even in 1.10.x. I remember that Brice was playing with configuration in 2.x, but MockitoConfiguration seems still to be available.
+1000. The question is: why was this not the default from the beginning? Why was Mockito ever released with a different default?
I just wasted more than an hour trying to understand:
- how can a method whose code never returns
null, under any circumstance, could return null, resulting in an impossible-to-happenNullPointerException? - why is my debugger not stopping inside this method?
I was lucky that a colleague noticed that the method is on a mock.
Please, please, PLEASE!!! make this the default. For the sanity of your users :)
P.S.: thanks @szpak for pointing a way to make this a global default.