Having recently returned from a Test Driven Development (TDD) course I had the following thought.While writing unit tests using Mockito we came up against of the problem of mocking static methods. It was suggested by one developer we use PowerMock, which allows mocking of static methods, and then we got into a big discussion on how we should approach this problem.However, in my experience static methods should only really be used as utility type methods. The classic example in java being Math.random().So a static method should only, execute one defined action regardless of any interaction with a class instance. If this is not the case, and you require class instance interaction, your method should not be static and you need to rethink your design.So my question is, with this in mind should you need to mock static methods at all? If they are always performing a simple action, then surely you should just call them as you would in real code.
Mocking static methods
java;tdd;mocking;static methods