Instant Mock Testing with PowerMock

Discover unit testing using PowerMock

Instant Mock Testing with PowerMock

Starting
Deep Shah

Discover unit testing using PowerMock
$14.99
RRP $14.99
eBook
$29.99 p/month

Subscribe Now

Download this title FREE and instantly access over 3,500 courses today!

With unlimited access to a constantly growing library of over 3,500 courses, a subscription to Mapt gives you everything you need to get that next promotion or to land that dream job. Cancel anytime.

+ Collection
Free Sample

Book Details

ISBN 139781783289950
Paperback82 pages

Book Description

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.

Table of Contents

Chapter 1: Instant Mock Testing with PowerMock
Saying Hello World! (Simple)
Getting and installing PowerMock (Simple)
Mocking static methods (Simple)
Verifying method invocation (Simple)
Mocking final classes or methods (Simple)
Mocking constructors (Medium)
Understanding argument matchers (Medium)
Understanding the Answer interface (Advanced)

What You Will Learn

  • 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

Authors

Table of Contents

Chapter 1: Instant Mock Testing with PowerMock
Saying Hello World! (Simple)
Getting and installing PowerMock (Simple)
Mocking static methods (Simple)
Verifying method invocation (Simple)
Mocking final classes or methods (Simple)
Mocking constructors (Medium)
Understanding argument matchers (Medium)
Understanding the Answer interface (Advanced)

Book Details

ISBN 139781783289950
Paperback82 pages
Read More

Read More Reviews