* 初始化Spring环境- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
- @ContextConfiguration("classpath:baseBeans.xml")
- public class BaseTest extends AbstractTestNGSpringContextTests {
- // ...
- }
复制代码
* 子类也可以继承基类如下,则baseBase.xml和subBeans.xml里的beans都会初始化 - @ContextConfiguration("classpath:subBeans.xml")
- public class SubBaseTest extends BaseTest {
- // ...
- }
复制代码
* 测试用例类须继承基类
- public class ServiceTest extends SubBaseTest {
- // ...
- }
复制代码
* 附,spring-test包依赖
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- </dependency>
复制代码
|