项目不带Test包就得自己搞一个
pom.xml添加依赖
org.springframework.boot spring-boot-starter-test test
创建目录(src下跟main同级且要跟启动类同路径结构)
编写代码
@RunWith(SpringRunner.class) //如果此文件所在目录跟启动类所在目录不一致就要加上classes = FirmwareApplication.class //webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT是解决找不到spring上下文对象 @SpringBootTest(classes = FirmwareApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class Mytest { @Autowired private FirmwareServiceImpl firmwareServiceImpl; @Test public void hello(){ List> integerStringHashMap = firmwareServiceImpl.firmwareTypeRanking(); System.out.println(integerStringHashMap); } }
如果不加webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT就会出现下图报错java.lang.IllegalStateException: Failed to load ApplicationContext
不加@RunWith(SpringRunner.class)就会出现
上一篇:gtx 680 配什么cpu
下一篇:组装电脑什么配置合适