java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException when trying run junit5 test with maven

后端 未结 8 1843
抹茶落季
抹茶落季 2020-12-10 00:56

When trying to run tests using command mvn test I receive an error:

[ERROR] There was an error in the forked process
[ERROR] java.lang.NoClassDefFou         


        
相关标签:
8条回答
  • 2020-12-10 01:32

    I have commented the below part in pom.xml:

      <dependency>
          <groupId>org.junit.jupiter</groupId>
          <artifactId>junit-jupiter-api</artifactId>
          <version>5.3.2</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.junit.jupiter</groupId>
          <artifactId>junit-jupiter-engine</artifactId>
          <version>5.3.2</version>
          <scope>test</scope>
        </dependency>
    

    And I have added junit5 in java build path(project(right click->java build path->libraries->junit->junit5) It worked for me. Mine is spring-boot project.

    0 讨论(0)
  • 2020-12-10 01:38

    The following worked for me using surefire.plugin.version 2.22.2

    junit-jupiter artifact brings in all other necessary artifacts.

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.junit</groupId>
          <artifactId>junit-bom</artifactId>
          <version>5.5.2</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <scope>test</scope>
      </dependency>
      <!--Optional: Supports running Junit4 along with Junit5 -->
      <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
      </dependency>
    </dependencies>
    
    0 讨论(0)
提交回复
热议问题