标签:style io ar color sp java on art bs
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency>
添加一个父类,所有测试的类继承了这个类就可以用spring的注解。
import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:jdbc_beans.xml" }) public class SpringTest extends AbstractTransactionalJUnit4SpringContextTests { }
eg. 写测试类:
/** * @author 李永 * */ public class StudentTest extends SpringTest { @Autowired StudentDao studentDao; @Autowired CourseDao courseDao; @Autowired MyInsert insert; }
标签:style io ar color sp java on art bs
原文地址:http://my.oschina.net/liyonglee/blog/353920