51Testing软件测试论坛

标题: TestNG初始化Spring环境 [打印本页]

作者: 测试积点老人    时间: 2018-12-18 15:51
标题: TestNG初始化Spring环境
* 初始化Spring环境
  1. import org.springframework.test.context.ContextConfiguration;
  2. import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;

  3. @ContextConfiguration("classpath:baseBeans.xml")
  4. public class BaseTest extends AbstractTestNGSpringContextTests {
  5.     // ...
  6. }
复制代码

* 子类也可以继承基类

如下,则baseBase.xml和subBeans.xml里的beans都会初始化

  1. @ContextConfiguration("classpath:subBeans.xml")
  2. public class SubBaseTest extends BaseTest {
  3.     // ...
  4. }
复制代码

* 测试用例类须继承基类
  1. public class ServiceTest extends SubBaseTest {
  2.     // ...
  3. }
复制代码

* 附,spring-test包依赖
  1. <dependency>
  2.         <groupId>org.springframework</groupId>
  3.         <artifactId>spring-test</artifactId>
  4.         <version>${spring.version}</version>
  5. </dependency>
复制代码








欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2