Idea如何快速生成Junit测试类

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

2.步骤

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

 2.选择要执行的方法

3.生成如下测试代码

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

 代码:

@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = {APIApplication.class})
public class PddGoodsServiceImplTest {
    @Autowired
    private PddGoodsService pddGoodsService;

    @Test
    public void getGoodsById() {
        pddGoodsService.getGoodsById(456L);
    }

    @Test
    public void getGoodsList() {
    }

    @Test
    public void getGoodsUrl() {
    }
}

猜你喜欢

转载自www.cnblogs.com/qingmuchuanqi48/p/11853689.html