spring简单入门-springJUnit4ClassRunner
1.导入spring-test-5.1.5.RELEASE.jar(spring-test 的jar包,版本一致)
使用上次的项目:spring简单入门-注解
修改test.java
package com.zh.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.zh.service.impl.CustomerServiceImpl;
/**
* spring入门
* @author zh
*
*/
//RunWith使用SpringJUnit4ClassRunner替换原JUnit
//ContextConfiguration(指定配置文件)locations指定文件位置
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations= {"classpath:beans.xml"})
public class test {
@Autowired
private CustomerServiceImpl customerServiceImpl = null;
@Test
public void testSpring_test() {
customerServiceImpl.saveCustomer();
}
}
运行效果