Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用SpringExtension.BeforeAll时@BeforeAll的AbstractMethodError_Java_Spring Boot_Integration Testing_Junit5_Spring Boot Test - Fatal编程技术网

Java 使用SpringExtension.BeforeAll时@BeforeAll的AbstractMethodError

Java 使用SpringExtension.BeforeAll时@BeforeAll的AbstractMethodError,java,spring-boot,integration-testing,junit5,spring-boot-test,Java,Spring Boot,Integration Testing,Junit5,Spring Boot Test,当尝试使用Junit运行Spring Boot应用程序集成测试时,由于不允许使用@BeforeAll标记和@AfterAll标记,我遇到了以下错误 我一直在学习本教程,但由于Intellij没有正确地选择Jupiter runner,因此需要在POM中添加一些内容: 我的Pom依赖项是: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring

当尝试使用Junit运行Spring Boot应用程序集成测试时,由于不允许使用@BeforeAll标记和@AfterAll标记,我遇到了以下错误

我一直在学习本教程,但由于Intellij没有正确地选择Jupiter runner,因此需要在POM中添加一些内容:

我的Pom依赖项是:

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/>
</parent>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.0.0-M4</version>
        <scope>test</scope>
    </dependency>
    <!-- and the engine for surefire and failsafe -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.0.0-M4</version>
        <scope>test</scope>
    </dependency>

    <!-- Explicitly required for Intellij -->
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.0.0-M4</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-commons</artifactId>
        <version>1.0.0-M4</version>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.21.0</version>
        <scope>test</scope>
    </dependency>

</dependencies>

您使用的是JUnit 5
M4
(即里程碑版本4),该版本的Spring Boot不支持该版本

您应该使用JUnit平台1.1.1和JUnit Jupiter 5.1.1或更高版本的Spring Boot 2.0.3


请确保您也在使用Maven Surefire插件的版本
2.19.1
,如中所述。

使用版本1.1.1和5.1.1确实解决了我的问题,但发现我仍然需要使用Maven Surefire的较低版本19.1.0,因为Maven没有在版本2.22.0上进行测试。我还需要从16.0.3更新Intellij版本,以便能够运行我的任何JUnit5测试。很高兴你解决了这个问题!而且。。。很抱歉推荐了错误的Surefire版本。仅供参考:我更新了答案,指向5.1.1版本的用户指南,关于受支持的Surefire版本,应该是
2.19.1
(不是你提到的
19.1.0
,对吗?)。是的,我正在使用2.19.1,不确定我为什么说19.1.0。道歉
 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/>
</parent>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.0.0-M4</version>
        <scope>test</scope>
    </dependency>
    <!-- and the engine for surefire and failsafe -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.0.0-M4</version>
        <scope>test</scope>
    </dependency>

    <!-- Explicitly required for Intellij -->
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.0.0-M4</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-commons</artifactId>
        <version>1.0.0-M4</version>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.21.0</version>
        <scope>test</scope>
    </dependency>

</dependencies>
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class GameIntegrationTests {

    @Test
    public void test() {

    }
}