4 Migrating from JUnit 4 to JUnit 5

 

This chapter covers

  • Implementing the migration from JUnit 4 to JUnit 5
  • Working with a hybrid approach for mature projects
  • Comparing the needed JUnit 4 with JUnit 5 dependencies
  • Comparing the equivalent JUnit 4 with JUnit 5 annotations
  • Comparing JUnit 4 rules with JUnit 5 extensions

Nothing in this world can survive and remain useful without an update.

--Charles M. Tadros

So far, this book has introduced JUnit and its latest version, 5. We’ve discussed the core classes and methods and presented them in action so that you have a good understanding of how to build your tests efficiently. We’ve emphasized the importance of software architecture in general and shown the significant architectural changes between JUnit 4 and JUnit 5.

This chapter demonstrates how to make the step from JUnit 4 to JUnit 5 inside a project managed by our example company, Tested Data Systems Inc. The company keeps its customer information in a repository and addresses this repository to get the data. In addition, the company needs to track payments and other business rules.

JUnit 4 and JUnit 5 can work together within the same application. This fact is of particular benefit for implementing a migration in phases rather than all at once.

4.1 Migration steps between JUnit 4 and JUnit 5

4.2 Needed dependencies

4.3 Annotations, classes, and methods

4.3.1 Equivalent annotations, classes, and methods

4.3.2 Categories vs. tags

4.3.3 Migrating Hamcrest matcher functionality

4.3.4 Rules vs. the extension model

4.3.5 Custom rules

Summary

sitemap