From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Set up JUnit 5 in your Java application

- [Instructor] Let's set up Junit 5 in a Java application. To start, we'll open up our code in GitHub Codespaces. This sample application already has Maven set up for us. To add tests with JUnit, we'll need to add it as a dependency in our application. Maven lets us add dependencies in the POM file. This dependency includes the JUnit Jupiter API, which is essential for writing and executing JUnit 5 tests. To enable the Maven tool to execute these tests, we'll also configure the Maven Surefire Plugin in the same file. Our POM file is now all set up. To make sure this is synchronized with our application, let's run a Maven clean in the terminal. This command cleans the directory, removing any compiled sources, resources and test results. It ensures a clean build environment. We also have the Java Test Runner Extension already enabled. This is an extension specific to VS Code, and it allows us to run our tests directly in the editor. And with that, our environment is ready for us to write our first JUnit test.

Contents