IDEA 使用Junit 测试方法

1.选中 方法,右击=》GOTO=》Test=》Create New test, 勾选你要测试的方法

2.

@RunWith(SpringJUnit4ClassRunner.class) //表示这是一个Spring的测试类
@ContextConfiguration("classpath:applicationContext.xml") //定位Spring的配置文件
public class CategoryTest {

    @Autowired
    CategoryService categoryService;
    @Test
    public void addTwo() throws Exception {
        categoryService.addTwo();
    }

3,在测试类上一定要加上注解,否则空指针

posted @ 2018-07-18 17:32  王某人i  阅读(1381)  评论(0编辑  收藏  举报