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

前端 未结 30 2459
盖世英雄少女心
盖世英雄少女心 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:33

    Answers so far did not adress the problem of sharing code with other people who don't necessarily use Eclipse. Here is one proposition. The key is to use a maven profile to solve the Eclipse Case.

    It assumes you have defined a property junit5.version in your pom like:

    
        UTF-8
        5.1.1
    
    

    then in the profiles section add the following:

    
        
            eclipse
            
                
                    org.junit.jupiter
                    junit-jupiter-engine
                
                
                    org.junit.platform
                    junit-platform-launcher
                
            
            
                
                    
                        org.junit.jupiter
                        junit-jupiter-engine
                        ${junit5.version}
                        test
                    
                    
                        org.junit.platform
                        junit-platform-launcher
                        1.1.1
                        test
                    
                
            
        
    
    

    All you have to do after this is to select the profile in your local Eclipse: Right click on your project and select Maven > Select Maven Profiles... (or hit Ctrl + Alt + P), and then check the "eclipse" profile we just created.

    With that you are done. Your Eclipse will run Junit 5 tests as expected, but the configuration you added won't pollute other builds or other IDE

提交回复
热议问题