Test-Driven Development with Mockito
暫譯: 使用 Mockito 的測試驅動開發

Sujoy Acharya

  • 出版商: Packt Publishing
  • 出版日期: 2013-11-25
  • 售價: $1,690
  • 貴賓價: 9.5$1,606
  • 語言: 英文
  • 頁數: 172
  • 裝訂: Paperback
  • ISBN: 1783283297
  • ISBN-13: 9781783283293
  • 相關分類: TDD 測試導向開發
  • 海外代購書籍(需單獨結帳)

相關主題

商品描述

Learn how to apply Test-Driven Development and the Mockito framework in real life projects, using realistic, hands-on examples

Overview

  • Start writing clean, high quality code to apply Design Patterns and principles
  • Add new features to your project by applying Test-first development- JUnit 4.0 and Mockito framework
  • Make legacy code testable and clean up technical debts

In Detail

The usual life cycle of code involves adding code, breaking an existing functionality, fixing that and breaking a new area! This fragility can be fixed using automated tests and Test Driven Development.

TDD’s test first approach expedites the development process and unit tests act as safety nets for code refactoring and help in maintaining and extending the code. This makes TDD highly beneficial for new projects.

This practical, hands-on guide provides you with a number of clear, step-by-step exercises that will help you to take advantage of the real power that is behind Test Driven Development and the Mockito framework. By using this book, you will gain the knowledge that you need to use the Mockito framework in your project.

This book explains the concept of Test Driven Development (TDD), including mocking and refactoring, as well as breaking down the mystery and confusion that surrounds the test first approach of TDD. It will take you through a number of clear, practical examples that will help you to take advantage of TDD with the Mockito framework, quickly and painlessly.

You will learn how to write unit tests, refactor code and remove code smells. We will also take a look at mock objects and learn to use Mockito framework to stub, mock, verify and spy objects for testability. You will also learn to write clean, maintainable, and extensible code using design principles and patterns.

If you want to take advantage of using Test Driven Development and learn about mocking frameworks, then this is the book for you. You will learn everything you need to know to apply Test Driven Development in a real life project, as well as how to refactor legacy code and write quality code using design patterns.

What you will learn from this book

  • Create your first unit test and discover the power of unit testing
  • Familiarize yourself with Test-first Development and the refactoring process
  • Add new features to your project applying Test Driven Development
  • Create readable, maintainable, and extensible software using design principles and patterns
  • Start stubbing, mocking, spying, and verifying objects using Mockito APIs
  • Apply inside-out and outside-in TDD styles
  • Expedite the development process using Eclipse and keyboard shortcuts
  • Apply JUnit 4.0 and advanced Mockito features – argument captor, callbacks, and answers

Approach

This book is a hands-on guide, full of practical examples to illustrate the concepts of Test Driven Development.

Who this book is written for

If you are a developer who wants to develop software following Test Driven Development using Mockito and leveraging various Mockito features, this book is ideal for you. You don’t need prior knowledge of TDD, Mockito, or JUnit.

It is ideal for developers, who have some experience in Java application development as well as a basic knowledge of unit testing, but it covers the basic fundamentals of TDD and JUnit testing to get you acquainted with these concepts before delving into them.

商品描述(中文翻譯)

學習如何在實際專案中應用測試驅動開發(Test-Driven Development, TDD)和 Mockito 框架,使用真實的、實作的範例。

概述
- 開始撰寫乾淨、高品質的程式碼,以應用設計模式和原則
- 通過應用測試優先開發(Test-first development)來為專案新增功能 - JUnit 4.0 和 Mockito 框架
- 使舊有程式碼可測試並清理技術負債

詳細內容
程式碼的通常生命週期涉及添加程式碼、破壞現有功能、修復該功能並破壞新的區域!這種脆弱性可以通過自動化測試和測試驅動開發來修復。

TDD 的測試優先方法加快了開發過程,單元測試作為程式碼重構的安全網,幫助維護和擴展程式碼。這使得 TDD 對於新專案非常有利。

這本實用的手冊提供了多個清晰的逐步練習,幫助您利用測試驅動開發和 Mockito 框架背後的真正力量。通過使用這本書,您將獲得在專案中使用 Mockito 框架所需的知識。

本書解釋了測試驅動開發(TDD)的概念,包括模擬(mocking)和重構(refactoring),並解開圍繞 TDD 測試優先方法的神秘與困惑。它將帶您通過多個清晰、實用的範例,幫助您快速且輕鬆地利用 TDD 和 Mockito 框架。

您將學會如何撰寫單元測試、重構程式碼和消除程式碼異味。我們還將查看模擬物件,學習如何使用 Mockito 框架來存根(stub)、模擬、驗證和監視(spy)物件以提高可測試性。您還將學會使用設計原則和模式撰寫乾淨、可維護和可擴展的程式碼。

如果您想利用測試驅動開發並學習模擬框架,那麼這本書就是為您而寫。您將學到在實際專案中應用測試驅動開發所需的所有知識,以及如何重構舊有程式碼並使用設計模式撰寫高品質程式碼。

您將從這本書中學到的內容
- 創建您的第一個單元測試,發現單元測試的力量
- 熟悉測試優先開發和重構過程
- 通過應用測試驅動開發為專案新增功能
- 使用設計原則和模式創建可讀、可維護和可擴展的軟體
- 開始使用 Mockito API 進行存根、模擬、監視和驗證物件
- 應用內部優先和外部優先的 TDD 風格
- 使用 Eclipse 和鍵盤快捷鍵加快開發過程
- 應用 JUnit 4.0 和進階的 Mockito 功能 - 參數捕獲(argument captor)、回調(callbacks)和答案(answers)

方法
這本書是一本實作指南,充滿了實用範例來說明測試驅動開發的概念。

本書的讀者對象
如果您是一位希望使用 Mockito 進行測試驅動開發並利用各種 Mockito 功能的開發者,這本書非常適合您。您不需要具備 TDD、Mockito 或 JUnit 的先前知識。

這本書非常適合有一定 Java 應用程式開發經驗以及基本單元測試知識的開發者,但它涵蓋了 TDD 和 JUnit 測試的基本原則,以便在深入這些概念之前讓您熟悉它們。