Although these situations should not take place in a well-written and test-driven system, there are cases in which it is necessary to mock some legacy code or third-party libraries that are impossible to be mocked only by means of Mockito. In this recipe, we will see how to deal with those abnormal situations using the PowerMock
library. Remember, however, that this tool is extremely powerful and the very need to use it suggests that something may really be wrong with your code. The best outcome of using this library would be to use it as means to refactor the bad code and, at the end of the day, remove the PowerMock dependency from the system since it is no longer needed.
Mockito Cookbook
By :
Mockito Cookbook
By:
Overview of this book
Table of Contents (17 chapters)
Mockito Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
Getting Started with Mockito
Creating Mocks
Creating Spies and Partial Mocks
Stubbing Behavior of Mocks
Stubbing Behavior of Spies
Verifying Test Doubles
Verifying Behavior with Object Matchers
Refactoring with Mockito
Integration Testing with Mockito and DI Frameworks
Mocking Libraries Comparison
Index
Customer Reviews