java的Junit测试

来源:互联网 发布:红色网络家园 编辑:程序博客网 时间:2024/05/22 23:05

下面代码为junit测试示例,引用的jar包如下,是junit4。
注意:如果不是SpringBoot的项目,类上面注解需要用我注释掉的部分

package com.dion.service;import com.dion.StartController;import com.dion.interf.PersonService;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.SpringJUnit4ClassRunner;/** * Created by liyang on 2017/7/28. */@RunWith(SpringJUnit4ClassRunner.class)             //指定Junit@SpringBootTest(classes = StartController.class)    //指定启动器,将bean注入spring(SpringBoot专用)//@ContextConfiguration(locations = { "classpath:applicationContext.xml" })     //如果不是SpringBoot的项目,那就用这个注解指定spring的xml文件public class PersonServiceImplTest {    @Autowired    PersonService personService;    @Test    public void save() throws Exception {        System.out.println(personService);        personService.save(null);    }}