Working with PowerMock

Sometimes, we cannot unit test our code, as the special Java constructs hide the testing impediments (a LAN connection or database connection in a private method, final method, static method, or initialization block), such as private methods, final methods and classes, static methods and initialization blocks, new operator, and so on. We refactor code for testability (explained in the Designing for testability with Mockito section) and, sometimes, compromise a good design for the sole purpose of testability. For example, final classes and methods are avoided, private methods are converted to protected or default, or unnecessarily moved to a collaborator class, static methods are avoided completely, and so on. This is done ...

Get Mockito Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.