day38 20-Spring与Junit整合
package cn.itcast.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 cn.itcast.service.UserService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="classpath:applicationContext.xml")//这种方式的好处是不用你自己去加载配置文件了. //这种测试以后要习惯,结合Spring进行单元测试的时候都会使用这种方式. public class SpringTest { @Autowired//想用哪个类直接一注入就行了. private UserService userService; @Test public void demo1(){ userService.sayHello(); } }