[ACCEPTED]-How to mock a private inner class-mockito

Accepted answer
Score: 11

Your test is on methods, but it tests the 17 whole class behavior. If your inner class 16 is private then its an implementation detail. Something 15 that the test shouldn't know. It there's 14 a lot of behaviour in that inner-class and 13 you want to test it independently maybe 12 you should make it public and separate from 11 this class.

Maybe you think: but then... it's 10 a lot of code to test (a very big indivisible 9 thing), can't I test something smaller? Well... yes. Test 8 Driven Development mandates to make a minimal 7 implementation and add more code only if 6 you add more tests. So you start with some 5 test and minimal implementation and evolve 4 both of them until the tests have all the 3 specification and the code all the implementation.

So 2 don't worry about private inner classes. Test 1 your class contract!

More Related questions