比如我想要测试项目中的某一个类。
这边我具体到想测试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() {
}
}