SpringBoot项目的测试类
1.
package soundsystem; import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes=CDPlayerConfig.class) public class CDPlayerTest { @Autowired private CompactDisc cd; @Test public void cdShouldNotBeNull() { assertNotNull(cd); } }
CDPlayerTest
使用了Spring的SpringJUnit4ClassRunner
,以便在测试开始的时候自动创建Spring的应用上下文。
注解@ContextConfiguration
会告诉它需要在CDPlayerConfig
中加载配置。
因为CDPlayerConfig
类中包含了@ComponentScan
,因此最终的应用上下文中应该包含CompactDisc
bean。
2.
package com.baizhi.cmfz; import com.baizhi.cmfz.dao.BannerDao; import com.baizhi.cmfz.entiy.Banner; import com.baizhi.cmfz.service.BannerService; 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.SpringRunner; import java.util.Date; import java.util.List; import java.util.Map; @RunWith(SpringRunner.class) @SpringBootTest public class BannerTest { @Autowired private BannerDao dao; @Autowired private BannerService service; @Test public void test1(){ List<Banner> list = dao.selectAllBanner(1,10,null); for (Banner banner : list) { System.out.println(banner); } } }
其中类SpringRunner继承了了SpringJUnit4ClassRunner
SpringBoot项目的测试类的更多相关文章
- SpringBoot项目中普通类获取http相关的类(request/response/session)
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...
- application/octet-stream二进制流, springboot项目, postman 测试参数设置
这里使用 原生String接受,之后解析,
- spring boot项目如何测试,如何部署
有很多网友会时不时的问我,spring boot项目如何测试,如何部署,在生产中有什么好的部署方案吗?这篇文章就来介绍一下spring boot 如何开发.调试.打包到最后的投产上线. 开发阶段 单元 ...
- 【快学springboot】1.快速创建springboot项目
若图片查看异常,请前往掘金查看:https://juejin.im/post/5d00e793f265da1b614ff10b 使用spring initialize工具快速创建springboot项 ...
- springboot 测试类,项目使用shiro时报错UnavailableSecurityManagerException
大概的问题就是,正常运行项目是没有问题的 使用测试类是,加载不了shiro的securityManager,主要导致不是很清楚,望告知, 解决方法 @Resource org.apache.shiro ...
- JPA实体类注解、springboot测试类、lombok的使用
前提准备: 搭建一个springboot项目,详情请参见其它博客:点击前往 1 引入相关依赖 web.mysql.jpa.lombok <?xml version="1.0" ...
- 学习springboot整合mybatis并编写测试类
报名立减200元.暑假直降6888. 邀请链接:http://www.jnshu.com/login/1/20535344 邀请码:20535344 遇到的问题: 1.原因是在启动类上只有一个@Map ...
- SpringBoot高版本修改为低版本时测试类报错解决
有时在使用idea通过Spring Initailizr创建项目时,默认只能创建最近的版本的SpringBoot项目. 这是如果想要换成版本,就可以在项目创建好了之后,在pom文件中直接将版本修改过来 ...
- Springboot测试类之@RunWith注解
@runWith注解作用: --@RunWith就是一个运行器 --@RunWith(JUnit4.class)就是指用JUnit4来运行 --@RunWith(SpringJUnit4ClassRu ...
随机推荐
- mysql创建存储过程动态SQL语句
DROP PROCEDURE IF EXISTS x.`wk`; DELIMITER $$ CREATE PROCEDURE `x`.`wk`() BEGIN ); ); SET t = CONCAT ...
- Python【每日一问】26
问: [基础题]:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数 [提高题]:一球从 100 米高度自由落下,每次落地后反跳回原高度的一半:再落下,求它在第 10 次落地时,共经过多 ...
- storm单节点问题(转载)
一.storm nimbus 单节点问题概述 1.storm集群在生产环境部署之后,通常会是如下的结构: 从图中可以看出zookeeper和supervisor都是多节点,任意1个zookeeper节 ...
- [转帖]/var/log/wtmp文件的作用
/var/log/wtmp文件的作用 https://blog.51cto.com/oldyunwei/1658778 /var/log/wtmp是一个二进制文件,记录每个用户的登录次数和持续时间 ...
- 第十六节:Asp.Net Core中Session的使用、扩展、进程外Session
一. 简介 关于Session的原理可参照Asp.Net版本Session的文章,去查阅. 1. 普通用法 (1).通过Nuget引入[Microsoft.AspNetCore.Http]程序集,Co ...
- 解决:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];
简记 使用SkyWalking用ES做存储,发现运行一段时间会提示ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index ...
- JDK9对集合添加的优化
JDK9对集合添加的优化 JDK9的新特性: list接口,Set接口,Map接口:里边增加了一个静态的方法of,可以给集合一次性添加多个元素 static <E> List<E&g ...
- 【在 Nervos CKB 上做开发】Nervos CKB 脚本编程简介[5]:调试 debug
作者:Xuejie 原文链接:https://xuejie.space/2019_10_18_introduction_to_ckb_script_programming_debugging/ Ner ...
- Mysql系列(六)—— MySQL索引介绍
前言 索引种类 索引维护 如何使用索引 一.索引索引种类 MySQL中索引主要包含以下几种: 普通索引 唯一索引 主键索引 联合索引 全文索引 二.索引维护 在简述了索引的类型后,再来了解下如何维护索 ...
- HTML 引用大全
路径logo <link rel="icon" href="../framework7-4.4.10/kitchen-sink/core/img/ztjs.png& ...