A few weeks ago someone from Packt publishing contacted me offering me a free copy of Instant mock testing with PowerMock if I accepted to write a review afterwards. Since I’ve been lately suffering with Unit Testing on Android I accepted and here is my review.
The book is really short and focused, which made it a very fast ready. I like this because I don’t really want to spend a lot of time learning how to mock something, it should be really straight forward.
Things I liked:
- Shows you how to install it for most common IDEs and also using maven (Non of these applied to me, but it should be good for most people)
- Shows short concise examples of how to mock different things
- It covers the things I consider most important about PowerMock: static, private and final methods
- Breaking the encapsulation chapter. I didn’t know that was possible
Things I would have liked to see:
- Examples using the EasyMock extension
- An example explaining what you would have to do if you didn’t have PowerMock and then show how PowerMock makes it easier
- I needed to partial mock a static method and I didn’t find an example for that
Overall I think it is a good quick read that is worth it if you are going to be writing unit tests for Java. It puts most of the information you will need about mocking in one place and will probably make your life easier if you have never used PowerMock.