spring cloud项目,想进行测试,依赖已添加了
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
项目中的libraries中已有junit 4.12.jar包和spring-boot-starter-test-1.3.8.RELEASE.jar包和spring-test-4.2.8RELEASE.jar包。
但是进行测试的,@RunWith()可以使用,但是无论是SpringJUnit4ClassRunner.class还是SpringRunner.class都无法import这两个包。请问怎么解决
spring-boot-starter-test的依赖包中应该包含了junit的依赖,有可能是版本冲突造成的,可以尝试着去掉Junit的依赖试试。
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.jege.spring.boot</groupId>
<artifactId>spring-boot-hello-world</artifactId>
<version>1.0.0.RELEASE</version>
<packaging>jar</packaging>
<name>spring-boot-hello-world</name>
<url>http://blog.csdn.net/je_ge</url>
<developers>
<developer>
<id>je_ge</id>
<name>je_ge</name>
<email>1272434821@qq.com</email>
<url>http://blog.csdn.net/je_ge</url>
<timezone>8</timezone>
</developer>
</developers>
<!-- 公共spring-boot配置,下面依赖jar文件不用在写版本号 -->
<parent>
<groupId>org.springframework.boot</groupId>
<!-- 自动包含以下信息: -->
<!-- 1.使用Java6编译级别 -->
<!-- 2.使UTF-8编码 -->
<!-- 3.实现了通用的测试框架 (JUnit, Hamcrest, Mockito). -->
<!-- 4.智能资源过滤 -->
<!-- 5.智能的插件配置(exec plugin, surefire, Git commit ID, shade). -->
<artifactId>spring-boot-starter-parent</artifactId>
<!-- spring boot 1.x最后稳定版本 -->
<version>1.4.1.RELEASE</version>
<!-- 表示父模块pom的相对路径,这里没有值 -->
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- web -->
<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>
<!-- 只在test测试里面运行 -->
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-boot-hello-world</finalName>
<plugins>
<!-- jdk编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>