The Startup
Published in

The Startup

Testing for Expected Exceptions in JUnit 5: Quite an Improvement

Photo by Emil Kalibradov on Unsplash

There are a few different ways to test that a constructor or other unit in a Java program throws a certain exception. JUnit 5 introduced a new way of testing for expected exceptions, which is an improvement from what was available for the purpose in previous versions.

Maybe with JUnit 4 you preferred the good old-fashioned Try-Catch with fail(). I did…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store