測試是保證代碼必不可少的環節,自己構建測試方法太慢,並且命名也不規范,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() { } }