Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory

前端 未结 30 2309
盖世英雄少女心
盖世英雄少女心 2020-11-29 22:31

The problem

Whenever I run my projects JUnit test (using JUnit 5 with Java 9 and Eclipse Oxygen 1.a) I encounter the problem that eclipse can\'t find any tests.

相关标签:
30条回答
  • 2020-11-29 23:18

    I'm using:

    Spring Tool Suite 4 Version: 4.4.2.RELEASE Build Id: 201911201053 Java version: 1.8.0_191

    and the message displayed is No tests found with test runner 'JUnit5'

    what worked for me was the configuration below

        <properties>
            <java.version>1.8</java.version>
            <junit-jupiter.version>5.5.2</junit-jupiter.version>
            <junit-platform.version>1.5.2</junit-platform.version>
        </properties> 
    
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter.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>
    
    0 讨论(0)
  • 2020-11-29 23:21

    SIMPLE FIX: (Add JUnit 5 Library)

    INSTRUCTIONS:

    • Right click on project -> Build Path -> Configure Build Path
    • In the pop-up -> Add Library -> JUnit -> JUnit 5 -> Finish -> Apply
    • You should see the JUnit 5 Library (and its jars) added to your project
    • Right click on project -> Maven -> Update Project -> OK
    0 讨论(0)
  • 2020-11-29 23:21

    When I change my jupiter api version into latest one, it was solved. Meanwhile, my eclipse and other eclipse extensions ide's (such as STS) is getting build path error. For every maven update, ide forces me to set the JRE System Library.

    0 讨论(0)
  • 2020-11-29 23:22

    In my case, the problem was myself and no IDE like Eclipse. I've imported the JUnit 4 Test class.

    So do NOT import this one:

    import org.junit.Test  // JUnit 4
    

    But DO import that one:

    import org.junit.jupiter.api.Test // JUnit 5
    
    0 讨论(0)
  • 2020-11-29 23:22

    I also faced the same issue you just need to add the library , Junit Library is already provided along with Eclipse so you just need to follow below

    Build Path > Configure Build Path > library > Add library > JUnit > Next > finish

    It works for me

    0 讨论(0)
  • It may cause by the version of junit-platform-launcher / junit-platform-runner.

    1.1.0 does not work

    1.4.1 works in my setup.

    I think this is a bug in eclipse as it is working with higher version libraries of junit and not other version.

    This resolved my issue. The other resolution looked less feasible or risky to me. Thanks.

    0 讨论(0)
提交回复
热议问题