万本电子书0元读

万本电子书0元读

顶部广告

Mastering Unit Testing Using Mockito and JUnit电子书

售       价:¥

10人正在读 | 0人评论 6.2

作       者:Sujoy Acharya

出  版  社:Packt Publishing

出版时间:2014-07-15

字       数:423.0万

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

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

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
A practical and easy-to-follow, yet comprehensive, guide to learning advanced JUnit testing. Each topic is explained and placed in context, and for the more inquisitive, there are more details of the concepts used. This book is for you if you are a developer with some experience in Java application development as well as a basic knowledge of JUnit testing. But for those whose skill set is void of any prior experience with JUnit testing, the book also covers basic fundamentals to get you acquainted with the concepts before putting them into practise.
目录展开

Mastering Unit Testing Using Mockito and JUnit

Table of Contents

Mastering Unit Testing Using Mockito and JUnit

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. JUnit 4 – a Total Recall

Defining unit testing

Working with JUnit 4

Setting up Eclipse

Running the first unit test

Exploring annotations

Verifying test conditions with Assertion

Working with exception handling

Exploring the @RunWith annotation

Working with JUnit 4++

Ignoring a test

Executing tests in order

Learning assumptions

Exploring the test suite

Asserting with assertThat

Comparing matchers – equalTo, is, and not

Working with compound value matchers – either, both, anyOf, allOf, and not

Working with collection matchers – hasItem and hasItems

Exploring string matchers – startsWith, endsWith, and containsString

Exploring built-in matchers

Building a custom matcher

Creating parameterized tests

Working with parameterized constructors

Working with parameterized methods

Giving a name

Working with timeouts

Exploring JUnit theories

Externalizing data using @ParametersSuppliedBy and ParameterSupplier

Dealing with JUnit rules

Playing with the timeout rule

Working with the ExpectedException rule

Unfolding the TemporaryFolder rule

Exploring the ErrorCollector rule

Working with the Verifier rule

Learning the TestWatcher rule

Working with the TestName rule

Handling external resources

Exploring JUnit categories

Summary

2. Automating JUnit Tests

Continuous Integration

Benefits of CI

Gradle automation

Getting started

Gradling

Ordering subtasks using doFirst and doLast

Default tasks

The task dependency

Daemon

Gradle plugins

The Eclipse plugin

The Java plugin

Maven project management

Installation

The Archetype plugin

The Project Object Model (POM) file

Project dependency

The build life cycle

Compiling the project

Testing the project

Packaging the project

The clean life cycle

The site life cycle

Another neat tool (Ant)

Jenkins

The Gradle project

The Maven project

Building the Ant project

Summary

3. Test Doubles

Dummy

Stub

Fake

Mock

Spy

Summary

4. Progressive Mockito

Working with Mockito

Why should you use Mockito?

Qualities of unit testing

Drinking Mockito

Configuring Mockito

Mocking in action

Mocking objects

Stubbing methods

Verifying the method invocation

Why do we use verify?

Verifying in depth

Verifying zero and no more interactions

Using argument matcher

Why do we need wildcard matchers?

The ArgumentMatcher class

Throwing exceptions

Stubbing consecutive calls

Stubbing with an Answer

Spying objects

Stubbing void methods

Capturing arguments with ArgumentCaptor

Verifying the invocation order

Changing the default settings

Resetting mock objects

Exploring Mockito annotations

Working with inline stubbing

Determining mocking details

Behavior-driven development with Mockito

Writing tests in BDD style

The BDD syntax

Summary

5. Exploring Code Coverage

Understanding code coverage

Learning the inner details of code instrumentation

Configuring the Eclipse plugin

Uncovering the Clover plugin

Working with the EclEmma plugin

Examining the eCobertura plugin

Measuring coverage using Gradle

Working with the Maven Cobertura plugin

Running the Cobertura Ant task

Summary

6. Revealing Code Quality

Understanding the static code analysis

Working with the Checkstyle plugin

Exploring the FindBugs plugin

Working with the PMD plugin

Monitoring code quality with SonarQube

Running SonarQube

Analyzing code with the SonarQube runner

Improving quality with the Sonar Eclipse plugin

Monitoring quality with Gradle and SonarQube

Monitoring quality with Maven and SonarQube

Monitoring quality with Ant and SonarQube

Getting familiar with false positives

Summary

7. Unit Testing the Web Tier

Unit testing servlets

Building and unit testing a J2EE web application

Playing with Spring MVC

Summary

8. Playing with Data

Separating concerns

Unit testing the persistence logic

Simplifying persistence with Spring

Verifying the system integrity

Writing integration tests with Spring

Summary

9. Solving Test Puzzles

Working with the legacy code

Working with testing impediments

Designing for testability

Identifying constructor issues

Realizing initialization issues

Working with private methods

Working with final methods

Exploring static method issues

Working with final classes

Learning the new attribute

Exploring static variables and blocks

Working with greenfield code

Summary

10. Best Practices

Writing meaningful tests

Improving readability

Breaking everything that could possibly break

Ignoring simple test cases

Verifying invalid parameters

Relying on direct testing

Staying away from debugging

Avoiding generic matchers

Keeping away from @ignore

Eluding debug messages

Automating JUnit tests

Configuring tests

Running in-memory tests

Staying away from Thread.sleep

Keeping unit tests away from the production code

Avoiding static variables

Assuming the test execution order

Loading data from files

Invoking super.setUp() and super.tearDown()

Staying away from side effects

Working with locales

Working with dates

Working with assertions

Using the correct assertion

Maintaining the assertEquals parameter order

Striving for one assertion per test

Handling exceptions

Working with test smells

Refactoring duplicates

Refactoring the test control logic

Removing the test logic from the production code

Refactoring over engineered tests

Summary

Index

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

发表评论

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

买过这本书的人还买过

读了这本书的人还在读

回顶部