How To Add JUnit 5 Dependency In Pom.xml

This article will tell you how to add the JUnit 5 java library into the eclipse project. It introduces two methods, one is to add the JUnit 5 java library as standalone jar files to the eclipse project, the other is how to add JUnit 5 dependency in pom.xml of the eclipse maven project.

1. How To Add JUnit 5 Java Library Into Eclipse Maven Project.

1.1 Add standalone JUnit library in the eclipse project.

  1. Create a java maven project using eclipse.
  2. Right-click the eclipse java project.
  3. Click the Properties menu item in the popup menu list.
  4. Click Java Build Path in the left panel.
  5. Click the Libraries tab in the right panel.
  6. Click the Add Library… button in the right panel.
  7. Choose JUnit in the popup Add Library dialog, then click the Next button.
  8. Choose JUnit5 from the JUnit library version drop-down list, then click Finish.
  9. Click the Apply and Close button in the eclipse Properties window to apply the changes.
  10. Now you can find the JUnit library jar files in the project-name/JUnit 5 subfolder in the eclipse left side Project Explorer panel.

1.2 How to add JUnit 5 dependency in pom.xml.

  1. To run JUnit 5 in an eclipse maven project, you need to add the below dependencies in the project pom.xml file.
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.4.0</version>
    </dependency>
    
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-runner</artifactId>
        <version>${junit.platform.version}</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>${junit.platform.version}</version>
        <scope>test</scope>
    </dependency>
  2. But the above maven dependencies configurations may throw an error like Missing artifact org.junit.platform:junit-platform-runner:jar: 5.4.0. You can see the error at the beginning of the <dependency> XML element, and when you mouse over the error, it will show the error message.
  3. The error means there is no artifact org.junit.platform:junit-platform-runner:jar: 5.4.0 in the central maven repository. So you should add the existing JUnit dependency jar file version for the dependency.
  4. Now you can follow section 2.1 to add JUnit standalone library jar files into you eclipse project, then find the related jar version under the project-name/JUnit 5 subfolder.
    eclipse maven project junit 5 standalone jar files
  5. From the above picture, we can see that the org.junit.platform group artifacts version should be 1.4.0. So we change the dependencies XML data to the below.
    <dependency>
        <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.0</version>
    </dependency>
    
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-runner</artifactId>
        <version>1.4.0</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.4.0</version>
        <scope>test</scope>
    </dependency>
  6. Now when you save the maven project, the Missing artifact org.junit.platform:junit-platform-runner:jar: 5.4.0 error should disappear.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x