O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

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

JUnit 4 runners

The JUnit 4's runner API also has an important deterrent. As described in chapter 1Retrospective on software quality and Java testingin JUnit 4 a runner is a Java class used to manage a test's life cycle. The runner API in JUnit 4 is quite powerful, nevertheless, it has an important drawback: runners are not composable, that is, we can only use a single runner at a time.

For example, a parameterized test cannot be combined with the Spring test support, due to the fact that both tests would use their own runner implementation. Thinking in Java (see the snippets given follow), each test case uses its own unique @RunWith annotation. The first one uses the Parameterized runner:

import org.junit.Test;import org.junit.runner.RunWith; ...

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