springboot如何单元测试

springboot如何单元测试

pom.xml加上单元测试的依赖

<!-- springboot test -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

加上一些注解点击运行就可以运行了

@RunWith(SpringRunner.class)
@SpringBootTest
public class Test {
	@Autowired
	CategoryDAO dao;
	
	@org.junit.Test
	public void test(){
		List<Category> cs = dao.findAll();
		
		for(Category c : cs){
			System.out.println("Name: " + c.name);
		}
	}
}

控制台显示结果

2019-11-24 11:50:22.684  INFO 7456 --- [pdateTask][T#1]] org.elasticsearch.gateway                : [Katherine Reynolds] recovered [0] indices into cluster_state
2019-11-24 11:50:22.913  INFO 7456 --- [           main] com.how2java.tmall.pojo.Test             : Started Test in 8.495 seconds (JVM running for 9.327)
2019-11-24 11:50:23.122  INFO 7456 --- [           main] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select category0_.id as id1_0_, category0_.name as name2_0_ from category category0_
Name: 瓦达瓦
Name: 123
Name: 12321
Name: 1
Name: 1
Name: 213
Name: 213
Name: 312
Name: 3
Name: 2
Name: 1
Name: 45
Name: 4
Name: 3
Name: 12
Name: 312123
Name: 123123
Name: 12
Name: 123123
Name: 12
Name: 12
Name: 12
Name: 12
Name: 12
Name: 12
Name: 12
Name: 12
Name: 请问请问
Name: 21
Name: 66
Name: 34534
Name: 1111
Name: 23123
Name: 132312
Name: 花好月圆夜
2019-11-24 11:50:23.268  INFO 7456 --- [       Thread-5] o.s.w.c.s.GenericWebApplicationContext   : Closing org.springframework.web.context.support.GenericWebApplicationContext@a370f4: startup date [Sun Nov 24 11:50:14 CST 2019]; root of context hierarchy
2019-11-24 11:50:23.271  INFO 7456 --- [       Thread-5] s.b.a.d.e.ElasticsearchAutoConfiguration : Closing Elasticsearch client
2019-11-24 11:50:23.271  INFO 7456 --- [       Thread-5] org.elasticsearch.node   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值