讲真这是个神奇的错误!java
并且我每一次在spring boot项目中成功启动junit!web
我用的是eclipse 2016的,之前用着也还好,会不会是eclipse的版本问题?spring
网上查了不少解决方案都不行。springboot
先来看看状况:eclipse
在maven dependencies 是由这个jar包的:maven
运行spring boot Test类:测试
package com.unicom.springboot.controller;this
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;3d
import junit.framework.TestCase;blog
//指定当前要测试的类
@SpringBootTest(classes=HelloController.class)
//// 指定实现测试的类
@RunWith(SpringJUnit4ClassRunner.class)
////@RunWith(SpringRunner.class)
//// 和web整合
@WebAppConfiguration
public class UserControllerTest {
@Autowired // 自动注入要测试的类
private HelloController helloController;
@Test
public void testHello() {
// 使用断言进行测试
TestCase.assertEquals(this.helloController.hello(), "hello");
}
}
采用junit方式运行结果以下:
为啥会从启动开始就一直报这个错?我将程序反复删除,就是报这个错。
我想了几方面的缘由,一,是否是eclipse版本老了?2、是否是spring boot的junit版本不兼容?3、maven的包有依赖冲突?
实际上根据这三个思路的解决方案,都没什么卵用。
而后我想了想,个人java项目都是直接在本地加个junit,要不试试。
果真,这样就能够了,可以正常运行了!
总结:eclipse的maven依赖有事可能不能再项目中被引用(缘由未知),如junit,手工添加就能够了。