小编tho*_*oer的帖子

当使用maven-surefire运行测试时,在@BeforeClass之后发生Spring-Autowiring

我在依赖注入(Spring autowiring)和maven-surefire方面遇到了一些问题.使用TestNG在eclipse中运行时,以下测试没有问题:注入service-object,然后@BeforeClass调用-method.

@TransactionConfiguration(defaultRollback=false)
@ContextConfiguration(locations={"/testContext.xml"})
public class MyServiceTest extends AbstractTransactionalTestNGSpringContextTests {


@Autowired
private MyService service;

@BeforeTest
public void setup() {
    System.out.println("*********************"+service);
    Assert.assertNotNull(service);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我使用maven-surefire运行相同的测试用例时,首先调用setup(),这会导致测试失败:

[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ myserver ---
[INFO] Surefire report directory: D:\...
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
**************************null
2011-03-04 11:08:57,462 DEBUG  ionTestExecutionListener.prepareTestInstance  - Performing dependency injection for test context [[TestContext@1fd6bea...
2011-03-04 11:08:57,462 DEBUG  ractGenericContextLoader.loadContext          - Loading ApplicationContext for locations [classpath:/testContext.xml].
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?如果我更换@BeforeClass@Test它在行家的作品作为TestNG的Eclipse插件.

Maven的万无一失,插件:2.7.2

Eclipse:Helios Service Release 1

jdk1.6.0_14 …

java testng spring spring-test maven

21
推荐指数
3
解决办法
1万
查看次数

标签 统计

java ×1

maven ×1

spring ×1

spring-test ×1

testng ×1