IntelliJ IDEA快速自动生成Junit测试类

1.背景

  测试是保证代码必不可少的环节,自己构建测试方法太慢,并且命名也不规范,idea中提供了,一键构建测试结构的功能...废话不多说,直接写步骤

2.步骤

  1.在需要做测试的类的当前窗口,直接按快捷键:按ctrl+shift+t –> create new test

  

  2.选择要执行的方法

  

  3.生成如下测试代码

  

  4.如果是基于容器(spring或springboot)测试,则需要添加注解

  

  代码:

 1 @RunWith(SpringRunner.class)
 2 @SpringBootTest
 3 @ContextConfiguration(classes = {APIApplication.class})
 4 public class PddGoodsServiceImplTest {
 5     @Autowired
 6     private PddGoodsService pddGoodsService;
 7 
 8     @Test
 9     public void getGoodsById() {
10         pddGoodsService.getGoodsById(456L);
11     }
12 
13     @Test
14     public void getGoodsList() {
15     }
16 
17     @Test
18     public void getGoodsUrl() {
19     }
20 }

 

  完美!

 

posted @ 2019-07-18 10:47  李东平|一线码农  阅读(21032)  评论(0编辑  收藏  举报