3

我将 Junit 5.5.1 添加到一个使用 4.11 的项目中。我编写的测试直到今天都运行良好。今天,即使在执行任何测试类之前,所有测试都以退出代码 -1 失败。我不知道任何会导致这种情况的依赖关系发生变化。

我切换到 5.6.0-RC1,它似乎缺少一个扩展类 (TestInstancePreDestroyCallback)。

然后我尝试注意到 5.5.2 并切换到它:它与 5.5.1 有相同的问题。

我又试了一次 5.6.0-RC1 - 这次我注意到 jar 被命名为 5.6.0-M1。这个版本有效,所以我似乎没事,但那是一系列令人不安且不鼓舞人心的事件。

我的问题是:这是否发生在其他人身上,究竟是什么?

更新:原来 5.6.0-M1 中缺少的类存在于 5.6.0-RC1 中,所以我已经切换到它。我不再追究 5.5.* 的问题了。

4

3 回答 3

4

就我而言,我收到此错误是因为我已将两者都包含在我的 Spring Boot 应用程序中

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

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

我删除了后者,它对我来说很好。

于 2020-03-21T10:27:46.247 回答
2

我正在为这个问题拉头发。起初,我错过了这种依赖

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

但即使我拥有所有正确的依赖项,它也没有解决这个错误。最后,我决定在 intelliJ 中使缓存无效并重新启动(文件-> 使缓存无效/重新启动)并且它起作用了。不知道到底发生了什么,但那是我的解决方案。

最终,这是我的 JUnit/Mockito 依赖项:

       <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>1.6.2</version>
            <scope>test</scope>
        </dependency>
于 2020-04-23T16:46:34.617 回答
0

就我而言,它是木星依赖项。

你应该有:

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>

或者:

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
于 2020-09-07T09:33:30.820 回答