万本电子书0元读

万本电子书0元读

顶部广告

Mockito Cookbook电子书

售       价:¥

3人正在读 | 0人评论 9.8

作       者:Marcin Grzejszczak

出  版  社:Packt Publishing

出版时间:2014-06-24

字       数:188.2万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
This is a focused guide with lots of practical recipes with presentations of business issues and presentation of the whole test of the system. This book shows the use of Mockito's popular unit testing frameworks such as JUnit, PowerMock, TestNG, and so on. If you are a software developer with no testing experience (especially with Mockito) and you want to start using Mockito in the most efficient way then this book is for you. This book assumes that you have a good knowledge level and understanding of Java-based unit testing frameworks.
目录展开

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

累计评论(0条) 1个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部