Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Testing with JUnit

You're reading from   Testing with JUnit Master high quality software development driven by unit tests

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781782166603
Length 200 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Leonard Przybylski Leonard Przybylski
Author Profile Icon Leonard Przybylski
Leonard Przybylski
 Appel Appel
Author Profile Icon Appel
Appel
Arrow right icon
View More author details
Toc

Using test helpers


Besides components, collaborators, data types, and test cases, we occasionally need another category of classes to write our tests efficiently. These utility classes provide any kind of testing related functionality that we want to reuse in several tests. This section explains some of the common practices.

Motivation

While writing tests, we'll inevitably find ourselves in a situation were we'll code the same routine for fixture setup, verification, or the like. If this happens to be in the same test case, we can extract a method for common usage. But sometimes, we could also make use of these methods in other test classes.

Java provides class inheritance, and so it's possible to introduce a common super type supplying these helping methods. After that, a particular test case can extend from this type and reuse the testing related functionality. Problem solved, right?

Wrong! First of all, inheritance is more than what the compiler checks. Class hierarchies represent abstract...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images