Java Junit 5.5.1和5.5.2突然无法运行测试:;流程结束,退出代码为-1“;;5.6.0-RC1缺少一个类

Java Junit 5.5.1和5.5.2突然无法运行测试:;流程结束,退出代码为-1“;;5.6.0-RC1缺少一个类,java,junit5,junit5-extension-model,Java,Junit5,Junit5 Extension Model,我将JUnit5.5.1添加到一个使用4.11的项目中。直到今天,我写的测试都运行得很好。今天,即使在执行任何测试类之前,所有测试都以退出代码-1失败。我不知道会导致这种情况的任何依赖项更改 我切换到5.6.0-RC1,它似乎缺少一个扩展类(TestInstancePreDestroyCallback) 然后我试着注意到5.5.2并切换到它:它与5.5.1有相同的问题 我又试了一次5.6.0-RC1,这次我注意到这个罐子的名字是5.6.0-M1。这个版本奏效了,所以我看起来还行,但那是一系列令人

我将JUnit5.5.1添加到一个使用4.11的项目中。直到今天,我写的测试都运行得很好。今天,即使在执行任何测试类之前,所有测试都以退出代码-1失败。我不知道会导致这种情况的任何依赖项更改

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

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

我又试了一次5.6.0-RC1,这次我注意到这个罐子的名字是5.6.0-M1。这个版本奏效了,所以我看起来还行,但那是一系列令人不安、不自信的事件

我的问题是:这发生在其他人身上了吗?到底是什么


更新:发现5.6.0-M1中缺少的类在5.6.0-RC1中存在,所以我切换到它。我不再继续研究5.5.*问题。

在我的例子中,我遇到了这个错误,因为我在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>

org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机


org.junit.jupiter
朱尼特木星发动机
5.6.0
测试

我去掉了后者,效果很好。

这个问题让我毛骨悚然。起初,我缺少这种依赖性

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

org.junit.jupiter
JUnitJupiter api
5.6.2
测试
但即使我有所有正确的依赖项,它也没有修复这个错误。最后,我决定,在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>

org.mockito
莫基托磁芯
3.3.3
测试
org.mockito
莫基托朱庇特酒店
3.3.3
测试
org.junit.jupiter
JUnitJupiter api
5.6.2
测试
org.junit.jupiter
朱尼特木星发动机
5.6.2
测试
org.junit.platform
junit平台跑步者
1.6.2
测试

在我的例子中是jupiter依赖关系

你应该:

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

org.junit.jupiter
朱尼特朱庇特
5.6.2
测试
或:


org.junit.jupiter
朱尼特木星发动机
5.6.2
测试
org.junit.jupiter
JUnitJupiter api
5.6.2
测试

请显示您的依赖项(Gradle或Maven文件)以及收到的确切错误消息。乍一看,这更可能是编译/构建问题,而不是JUnit问题。恐怕我的公司认为依赖项是专有的。但是下面是关于5.6.0问题的详细信息:
java.lang.NoClassDefFoundError:org/junit/jupiter/api/extension/TestInstancePreDestroyCallback
它不在M1 jar中:
$jar tf junit-jupiter-api-5.6.0-M1.jar | grep“api/extension/TestInstance”org/junit/jupiter/api/extension/TestInstanceFactory.class org/junit/jupiter/api/extension/TestInstances.class org/junit/jupiter/api/extension/TestInstancePostProcessor.class
但它出现在5.6.0-RC1中。因为5.6.0-RC1为我工作,我不会追求5.5.*突然中止的问题,我会建议更新版本候选。这让我朝着正确的方向前进。最后我去了5.6.1“清理”所有东西,它终于起作用了。这有点奇怪。
    <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>