课程: Complete Guide To Java Testing with JUnit 5 & Mockito

Manage dependencies with Maven

- [Instructor] When writing Java tests, there are many useful libraries that can simplify and enhance your testing efforts. To use these libraries in your Java application, you'll need a robust dependency management tool, and that's where Maven comes in. One of its core features is its ability to manage project dependencies. Proper dependency management ensures that your project has access to all the necessary libraries and frameworks while avoiding conflicts and keeping the build process efficient. Maven uses a project object model file or a POM file to manage a project's configuration. This file is the heart of any Maven project and contains information about the project and configuration details used by Maven to build the project. Let's take a look at an example POM. Here, we can see the basic configuration of the project. It has its own group ID that defines the organization that made the project and an artifact ID that denotes the name of the project. We can also define custom properties that can be referenced throughout the POM file and dependencies. Dependencies also include a group ID and artifact ID. In this example, org.junit.jupiter is the organization that created the dependency and junit-jupiter-api is the name of the project. We've also added a version here, so a specific version of the library is pulled into our application. This is pulled from our custom properties. The scope determines when the dependency is required. In this case, it's only needed for testing. Maven also offers several build plugins. Here, we have a plugin that lets you use Maven to compile your Java code. In this course, the main way we'll use this file is to add test libraries. Throughout the chapters, we'll add different libraries as dependencies so we can leverage them to write our automated tests.

内容