/images/avatar.jpg

David Vlijmincx | Senior software developer

I am a Senior developer, Public speaker, Java blogger, and Author

Lifecycle methods JUnit 5 and 4

Introduction In this post, I am going to show you how you can run methods before and after a test method runs. Junit offers 4 different annotations you can use to decide when a method runs during the lifecycle of a test. One annotation lets you run a method before all the other tests are started while another runs every time before a test is started. The annotations differ between JUnit 5 and 4, I will show how both of them work starting with JUnit 5.