售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Mockito Cookbook
Table of Contents
Mockito Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Mockito
Introduction
Adding Mockito to a project's classpath
How to do it...
See also
Getting started with Mockito for JUnit
Getting ready
How to do it...
How it works...
There's more...
See also
Getting started with Mockito for TestNG
Getting ready
How to do it...
How it works...
See also
Mockito best practices – test behavior not implementation
Getting ready
How to do it...
See also
Adding Mockito hints to exception messages (JUnit) (Experimental)
Getting ready
How to do it...
How it works...
Adding additional Mockito warnings to your tests (JUnit) (Experimental)
How to do it...
How it works...
2. Creating Mocks
Introduction
Creating mocks in code
Getting ready
How to do it...
How it works...
See also
Creating mocks with annotations
Getting ready
How to do it...
How it works...
See also
Creating mocks with a different default answer
Getting ready
How to do it...
How it works...
There's more...
See also
Creating mocks with different default answers with annotations
Getting ready
How to do it...
How it works...
See also
Creating mocks with custom configuration
Getting ready
How to do it...
How it works...
There's more...
See also
Creating mocks of final classes with PowerMock
Getting ready
How to do it...
How it works...
See also
Creating mocks of enums with PowerMock
Getting ready
How to do it...
How it works...
See also
3. Creating Spies and Partial Mocks
Introduction
Creating spies in code
Getting ready
How to do it...
How it works...
See also
Creating spies with custom configuration
Getting ready
How to do it...
How it works...
See also
Creating spies using annotations
Getting ready
How to do it...
How it works...
There's more...
See also
Creating partial mocks
Getting ready
How to do it...
How it works...
There's more...
See also
Creating partial mocks of final classes with delegatesTo()
Getting ready
How to do it...
How it works...
There's more...
See also
Creating spies of final classes with PowerMock
Getting ready
How to do it...
How it works...
See also
4. Stubbing Behavior of Mocks
Introduction
Using argument matchers for stubbing
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing methods that return values
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing methods so that they throw exceptions
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing methods so that they return custom answers
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing methods so that they call real methods
Getting ready
How to do it...
See also
Stubbing void methods
How to do it...
How it works...
See also
Stubbing void methods so that they throw exceptions
Getting ready
How to do it...
How it works...
See also
Stubbing void methods so that they return custom answers
Getting ready
How to do it...
How it works...
See also
Stubbing void methods so that they call real methods
Getting ready
How to do it...
How it works...
See also
Stubbing final methods with PowerMock
Getting ready
How to do it...
How it works...
See also
Stubbing static methods with PowerMock
Getting ready
How to do it...
How it works...
See also
Stubbing object instantiation using PowerMock
Getting ready
How to do it...
How it works...
See also
5. Stubbing Behavior of Spies
Introduction
Stubbing methods that return values
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing methods so that they throw exceptions
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing methods so that they return custom answers
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing void methods
Getting ready
How to do it...
How it works...
There's more...
See also
Stubbing void methods so that they throw exceptions
Getting ready
How to do it...
How it works...
See also
Stubbing void methods so that they return custom answers
Getting ready
How to do it...
How it works...
See also
Stubbing final methods with PowerMock
Getting ready
How to do it...
How it works...
See also
6. Verifying Test Doubles
Introduction
Verifying the method invocation count with times()
Getting ready
How to do it...
How it works...
There's more...
See also
Verifying the method invocation count with atLeast()
Getting ready
How to do it...
How it works...
There's more...
See also
Verifying the method invocation count with atMost()
Getting ready
How to do it...
How it works...
See also
Verifying that interactions never happened
Getting ready
How to do it...
How it works...
There's more...
See also
Verifying that interactions stopped happening
Getting ready
How to do it...
How it works...
There's more...
See also
Verifying the order of interactions
Getting ready
How to do it...
How it works...
There's more...
See also
Verifying interactions and ignoring stubbed methods
Getting ready
How to do it…
How it works...
See also
Verifying the method invocation within the specified time
Getting ready
How to do it…
How it works...
There's more...
See also
7. Verifying Behavior with Object Matchers
Introduction
Using Hamcrest matchers for assertions
Getting ready
How to do it...
How it works...
There's more...
See also
Creating custom Hamcrest matchers
Getting ready
How to do it...
How it works...
There's more...
See also
Using Hamcrest matchers for stubbing and verification
Getting ready
How to do it...
How it works...
There's more...
See also
Using AssertJ for assertions
Getting ready
How to do it...
How it works...
There's more...
See also
Creating custom AssertJ assertions
Getting ready
How to do it...
How it works...
There's more...
See also
Capturing and asserting the argument
Getting ready
How to do it...
How it works...
See also
8. Refactoring with Mockito
Introduction
Removing the problems with instance creation
Getting ready
How to do it...
How it works...
There's more...
See also
Refactoring classes that do too much
Getting ready
How to do it...
See also
Refactoring the classes that use the class casts
Getting ready
How to do it...
See also
Refactoring the classes that use static methods
Getting ready
How to do it...
See also
Refactoring the tests that use too many mocks
Getting ready
How to do it...
How it works..
There's more…
See also
9. Integration Testing with Mockito and DI Frameworks
Introduction
Injecting test doubles instead of beans using Spring's code configuration
Getting ready
How to do it...
How it works...
There's more...
See also
Injecting test doubles instead of beans using Spring's XML configuration
Getting ready
How to do it...
How it works...
See also
Injecting test doubles instead of beans using Springockito
Getting ready
How to do it...
How it works...
There's more...
See also
Injecting test doubles instead of beans with Guice
Getting ready
How to do it...
How it works...
See also
Injecting test doubles instead of beans with Guice using Jukito
Getting ready
How to do it...
How it works...
There's more...
See also
10. Mocking Libraries Comparison
Introduction
Mockito versus EasyMock
Getting ready
How to do it...
How it works...
There's more...
See also
Mockito versus JMockit
Getting ready
How to do it...
How it works...
There's more...
See also
Mockito versus JMock
Getting ready
How to do it...
How it works...
There's more...
See also
Mockito versus Spock
Getting ready
How to do it...
How it works...
There's more...
See also
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜