For over a decade JUnit 4 has been the go-to test framework for JVM-based software projects. You can find the use of JUnit across the board in organizations from big entprises to small startups. Despite its popularity, the test framework’s features barely moved with the times. Due to its deep penetration among the industry, evolutionary changes became harder and harder to implement without introducing inevidable breakages to the API.

With the rise of newer JVM languages like Groovy and Kotlin, feature-rich test frameworks emerged. The test framework Spock became a welcome alternative for many projects fearless to adopt Groovy as part of their polyglot software stack.

With the first GA release of JUnit 5 in September 2017, the JUnit team brought real innovation to the established space of testing JVM code. Not only is the release packed with new features comparable to the ones provided by Spock, JUnit 5 also serves as a platform for launching other test frameworks on the JVM.

In this blog post, I am going to compare typical testing usage patterns and features available for JUnit 5 and Spock. The content is not going to discuss the fundamental, methodological differences between JUnit 5 and Spock (behavior-driven development (BDD) vs. non-BDD). You can find all sample code in a dedicated repository on Github. All examples are based on JUnit 5.0.2 and Spock 1.1.