Instant Mock Testing with PowerMock
暫譯: 即時模擬測試與 PowerMock
Deep Shah
- 出版商: Packt Publishing
- 出版日期: 2013-11-02
- 售價: $1,190
- 貴賓價: 9.5 折 $1,131
- 語言: 英文
- 頁數: 82
- 裝訂: Paperback
- ISBN: 1783289953
- ISBN-13: 9781783289950
海外代購書籍(需單獨結帳)
相關主題
商品描述
Discover unit testing using PowerMock
Overview
- Learn something new in an Instant! A short, fast, focused guide delivering immediate results
- Understand how to test unit code using PowerMock, through hands-on-examples
- Learn how to avoid unwanted behaviour of code using PowerMock for testing
- Explore the features of PowerMock through the selection of clear, practical, step-by-step recipes
In Detail
Writing good unit tests can be hard in situations where we have to deal with static, final, or private methods. Sometimes, even a good design is sacrificed for the sake of testability. A mocking framework’ s ability to create mocks for almost any scenario enables us to focus on accurately programming for a business environment.
Starting with a basic example of how to create a mock and verify a method invocation Instant Testing with PowerMock then demonstrates various features of PowerMock using clear, practical, step-by-step recipes. By the end of this book, you will be able to write unit tests for almost any scenario and suppress unwanted behaviour to effectively unit test your code.
Moving on from the basics, you will learn to write unit tests for static, final, and private methods, and write flexible unit tests using argument matchers. Following on from this, you will also learn how to mock a few methods of a class, and invoke real implementation of others using partial mocks or spies. This book will teach you the tricks of the trade that will enable you to write good unit tests for a wide range of scenarios.
What you will learn from this book
- Learn how to mock final classes and methods
- Use argument matchers to write flexible tests
- Invoke private methods and verify the internal state of a class
- Suppress unwanted constructors, methods, fields, and static initializers
- Set up mocking code once and use Mock Policies to avoid writing repetitive code
Approach
Filled with practical, step-by-step instructions and clear explanations for the most important and useful tasks. A concise guide full of step-by-step recipes, to teach you how you can use PowerMock to unit test code.
Who this book is written for
If you are a beginner who would like to learn how to use PowerMock, this is the perfect guide for you! As the book comprehensively covers both basic and advanced concepts, this guide is also suitable for those of you who have an intermediate knowledge of PowerMock.
商品描述(中文翻譯)
發現使用 PowerMock 進行單元測試
概述
- 立即學習新知!一本短小、快速、專注的指南,提供即時結果
- 透過實作範例了解如何使用 PowerMock 測試單元程式碼
- 學習如何使用 PowerMock 進行測試以避免程式碼的不當行為
- 透過清晰、實用的逐步食譜探索 PowerMock 的功能
詳細內容
撰寫良好的單元測試在處理靜態、最終或私有方法的情況下可能會很困難。有時,甚至良好的設計也會為了可測試性而被犧牲。模擬框架能夠為幾乎任何情境創建模擬,使我們能夠專注於準確地為商業環境編程。
從基本範例開始,展示如何創建模擬並驗證方法調用,接著《使用 PowerMock 進行即時測試》將通過清晰、實用的逐步食譜展示 PowerMock 的各種功能。在本書結束時,您將能夠為幾乎任何情境撰寫單元測試,並抑制不當行為,以有效地對您的程式碼進行單元測試。
在掌握基礎後,您將學會為靜態、最終和私有方法撰寫單元測試,並使用參數匹配器撰寫靈活的單元測試。接下來,您還將學會如何模擬類別的幾個方法,並使用部分模擬或間諜調用其他方法的實際實現。本書將教您行業內的技巧,使您能夠為各種情境撰寫良好的單元測試。
您將從本書學到的內容
- 學習如何模擬最終類別和方法
- 使用參數匹配器撰寫靈活的測試
- 調用私有方法並驗證類別的內部狀態
- 抑制不必要的建構子、方法、欄位和靜態初始化器
- 一次設置模擬程式碼,並使用模擬政策以避免撰寫重複的程式碼
方法
本書充滿實用的逐步指導和對最重要、最有用任務的清晰解釋。一本簡明的指南,滿載逐步食譜,教您如何使用 PowerMock 進行程式碼的單元測試。
本書的讀者對象
如果您是希望學習如何使用 PowerMock 的初學者,這本書是您的完美指南!由於本書全面涵蓋基本和進階概念,因此對於那些對 PowerMock 具有中級知識的讀者來說,這本指南也非常合適。