有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

当类仅包含JUnit4注释时,java使Eclipse默认为JUnit4而不是JUnit5

最近的groovy升级带来了JUnit5,这导致Eclipse希望在JUnit5下运行每个测试。我可以通过运行配置并告诉Eclipse使用JUnit4来解决这个问题,但是这会变得很乏味

是否可以告诉Eclipse对特定项目(包括新的测试)始终使用JUnit4


共 (1) 个答案

  1. # 1 楼答案

    您可以指定一个概要文件并仅在Eclipse中激活它

    示例(假设您的问题是由对groovy-all的依赖性引起的):

        <profiles>
            <profile>
                <id>eclipse-groovy-no-junit5</id>
                <dependencyManagement>
                    <dependencies>
                        <dependency>
                            <groupId>${groovy.groupId}</groupId>
                            <artifactId>groovy-all</artifactId>
                            <version>${groovy.version}</version>
                            <type>pom</type>
                            <exclusions>
                                <exclusion>
                                    <groupId>${groovy.groupId}</groupId>
                                    <artifactId>groovy-test-junit5</artifactId>
                                </exclusion>
                            </exclusions>
                        </dependency>
                    </dependencies>
                </dependencyManagement>
            </profile>
        </profiles>
    

    然后去

    Project -> Properties -> Maven -> Active Maven Profiles

    并指定配置文件名eclipse-groovy-no-junit5

    备注:groovy.groupId设置为org.codehaus.groovy(这是一个变量,因为在4.x中它将被org.apache.groovy替换),并且groovy.version设置为3.0.8

    如果你想更详细一点,你可以添加

        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
    

    。。。但这是默认的