Skip to Content
Effective Unit Testing
book

Effective Unit Testing

by Lasse Koskela
February 2013
Intermediate to advanced content levelIntermediate to advanced
258 pages
7h 26m
English
Manning Publications
Content preview from Effective Unit Testing

A.1. A basic JUnit test class

In short, JUnit test classes are plain old Java classes that have one or more test methods and zero or more setup and teardown methods. JUnit also defines a simple lifecycle for executing the tests it finds.

The following sections will walk you through these fundamental elements of JUnit test classes one by one, starting with declaring test methods.

A.1.1. Declaring test methods

JUnit tests in their most basic incarnation are regular instance methods marked with a certain annotation. These methods exercise the code they’re testing and make assertions about expected conditions and side effects, making use of APIs provided by JUnit. The following listing shows an example of what a simple JUnit test class might look ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Art of Unit Testing, Second Edition

The Art of Unit Testing, Second Edition

Roy Osherove
Testing with JUnit

Testing with JUnit

Leonard Przybylski, Frank Appel

Publisher Resources

ISBN: 9781935182573Publisher SupportOtherPublisher WebsiteErrata PageSupplemental ContentPurchase Link