Book Image

Testing with JUnit

By : Leonard Przybylski, Frank Appel
Book Image

Testing with JUnit

By: Leonard Przybylski, Frank Appel

Overview of this book

Table of Contents (16 chapters)
Testing with JUnit
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Treating collaborators


Considerations we've made in Chapter 3, Developing Independently Testable Units, about how a software system can be built upon collaborating components, foreshadows that we have to take good care when modelling our overall strategy for exceptional flow. Because of this, we'll start this section with an introduction of the fail fast strategy, which is a perfect match to the test-first approach. The second part of the section will show you how to deal with checked exceptions thrown by collaborators.

Fail fast

Until now, we've learned that exceptions can serve in corner cases as an expected outcome, which we need to verify with tests. As an example, we've changed the behavior of our timeline fetch-count setter. The new version throws IllegalArgumentException if the given parameter is out of range. While we've explained how to test this, you may have wondered whether throwing an exception is actually an improvement.

On the contrary, you might think, doesn't the exception...