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,在测试类上一定要加上注解,否则空指针

猜你喜欢

转载自blog.csdn.net/joe_wang1/article/details/81102077