IDEA如何快速创建对应类的测试类

比如我想要测试项目中的某一个类。

这边我具体到想测试CategoryServiceImpl这个类,如下图:
在这里插入图片描述

只需要将双击这个类,鼠标右键,然后选择go to到Test.

在这里插入图片描述

点击,创建测试

在这里插入图片描述

然后勾选你想要测试的方法
在这里插入图片描述

点击确定之后

在这里插入图片描述

测试类和前面勾选的方法都已经自动生成了。

测试类快速创建完毕!!!

想要正常运行,还要注意,要在测试类上加

@RunWith(SpringRunner.class)
@SpringBootTest

这样才能正常运行!!!

如下图:

package com.lbl.service.Impl;

import com.lbl.dataObject.ProductCategory;
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;

@RunWith(SpringRunner.class)
@SpringBootTest
public class CategoryServiceImplTest {

    @Autowired
    private CategoryServiceImpl categoryService;

    @Test
    public void findOne() {
        ProductCategory result = categoryService.findOne(1);
        System.out.println(result);
//        Assert.assertEquals(new Integer(1),result.getCategoryId());
    }

    @Test
    public void findAll() {
    }

    @Test
    public void findByCatogoryTypeIn() {
    }

    @Test
    public void save() {
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值