O'Reilly logo

Testing with JUnit by Frank Appel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Improving Readability with Custom Assertions

In this chapter, you'll learn to write concise verifications that reveal the expected outcome of a test clearly. You'll be taught how domain-specific assertions help to improve readability and reduce boilerplate at the same time. To achieve this, you'll be given an overview of the respective capabilities and limitations of the various JUnit test verification techniques. In detail, you'll be introduced to the built-in mechanism, Hamcrest matchers, and AssertJ asserts. In this chapter, we will discuss the following topics:

  • Working with the JUnit built-in assert approach
  • Creating flexible expressions of intent with Hamcrest
  • Writing fluently readable assertions with AssertJ

Working with the JUnit ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required