Spring整合Junit

导入坐标


    org.springframework
    spring-context
    5.2.8.RELEASE


    org.springframework
    spring-test
    5.2.8.RELEASE


   junit
   junit
   4.12
   test

//替换原来的运行器,让测试运行于Spring测试环境
@RunWith(SpringJUnit4ClassRunner.class)
//加载spring核心配置文件
//@ContextConfiguration("classpath:applicationContext.xml")
//加载spring核心配置类
@ContextConfiguration(classes = {Configuration.class})
public class Test {

    //注入testService对象
    @Autowired
    private TestServiceImpl testService;

    @Test
    public void test1(){
        testService.test();
    }
}

你可能感兴趣的:(Spring整合Junit)