简体   繁体   English

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

[英]Make Eclipse default to JUnit4 rather than JUnit5 when the class only contains JUnit4 annotations

A recent upgrade of groovy which brought with it JUnit5 has resulting in Eclipse wanting to run every test under JUnit5.最近的 groovy 升级带来了 JUnit5,导致 Eclipse 想要在 JUnit5 下运行每个测试。 I can sort of work around this by going to run configurations and tell Eclipse to use JUnit4, however this gets tedious.我可以通过运行配置并告诉 Eclipse 使用 JUnit4 来解决这个问题,但这会变得乏味。

Is it possible to tell Eclipse to always use JUnit4 for a particular project, including new tests?是否可以告诉 Eclipse 始终将 JUnit4 用于特定项目,包括新测试?

在启动配置中,您应该能够根据需要选择JUnit 3、4或5。

You can specify a profile and activate it in Eclipse only.您只能在 Eclipse 中指定配置文件并激活它。

Example (assuming your problem arose by having a dependency to groovy-all ):示例(假设您的问题是由于依赖于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>

Then go to然后去

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

and specify the profile name eclipse-groovy-no-junit5 .并指定配置文件名称eclipse-groovy-no-junit5

Remark: groovy.groupId is set to org.codehaus.groovy (it's a variable, because it will be replaced by org.apache.groovy in 4.x) and groovy.version is set to 3.0.8 .备注: groovy.groupId设置为org.codehaus.groovy (它是一个变量,因为它会在 4.x 中被org.apache.groovy替换), groovy.version设置为3.0.8

If you want to be a bit more verbose, you can add...如果你想更详细一点,你可以添加...

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

...but it's the default anyway. ...但无论如何它都是默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM