Spring-test在测试中没有找到SpringRunner类

时间:2018-01-22 13:38:45

标签: spring-boot

当我使用SpringInitializr生成一个新项目并包含spring-test时,一切都很好......除了一件事。它创建的一个测试无法解析SpringRunner类。它包含一个@RunWith(SpringRunner.class),从我读过的所有内容中,这应该对spring-boot 1.5.9有效。这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT;     4.0.0

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</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>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我正在使用Eclipse。从我在Maven依赖项中看到的,事情看起来还不错。它使用的是spring-test-4.3.13.RELEASE.jar。我打开它,看到它有SpringRunner类。我有什么想法我做错了吗?我从SpringInitializr创建的任何项目都是相同的(我使用1.5.9默认值在SpringInitializer中创建它)

测试类是开箱即用的:

    package com.example.demo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {

    @Test
    public void contextLoads() {
    }

}

- UPDATE ...所以,我可以在pom.xml文件中恢复弹簧测试次要版本......从4.3.13到4.3.12并找到它。它似乎只是4.3.x主要版本的最新(推荐)版本。在这一点上,我有一个解决方法,但如果有人有想法,我想成为最新的。正如我上面提到的,我可以打开4.3.13 jar文件并找到SpringRunner类

1 个答案:

答案 0 :(得分:0)

将spring-boot-starter-parent更新为2.0.1.RELEASE

AppState.addEventListener('change', (nextAppState) => {
    if (nextAppState.match(/inactive|background/) && nextAppState === 'active') {
        console.log('App has come to the foreground! (iOS and Android)')
    }
});