Book Image

MOCKITO COOKBOOK

By : Grzejszczak
Book Image

MOCKITO COOKBOOK

By: Grzejszczak

Overview of this book

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.
Table of Contents (12 chapters)
11
Index

Mockito versus Spock


In this recipe, we will write a simple test using Spock that verifies the behavior of the system under test when an exception is thrown. Before going into details, it's worth mentioning that Spock is a Groovy-based (http://groovy.codehaus.org/) tool. Therefore, in order to use it, you need to know at least the basics of the Groovy language. Spock is based on JUnit and is much more than a mocking framework. It gives you a beautiful BDD (Behavior Driven Development) syntax that will convert your tests to Specifications (capital S since Specification is a class that you need to extend to work with Spock).

If you want to try out Spock without installing it on your machine, check out the Spock Web Console at http://meetspock.appspot.com/, where you can write your tests online!

Spock is a perfect tool for you if you want to introduce Groovy into your project. You can start off with writing tests and then gradually progress towards production code (if that is what you want, of...