我在依赖注入(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 …