1. jar 包支持
导入jar:spring-test-4.1.1.RELEASE.jar
2.写一个单元测试的类
package cn.itcast.aop.demo;
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 cn.itcast.aop.HelloService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:application-core.xml")
public class SpringTest {
@Autowired
private HelloService helloworld;
@Test
public void test(){
helloworld.sayHello("你好");
}
}
说明: 最好先引入@Test 注解,这样方便引入 @RunWith注解
注意两点:@RunWith SpringJunit4ClassRunner这个类和@ContextConfiguration就行,测试bean就直接注入就行