依存性注入 (Spring 自動配線) と maven-surefire に問題があります。次のテストは、TestNG を使用して Eclipse で実行すると問題なく機能します。サービス オブジェクトが注入され、次に@BeforeClass
メソッドが呼び出されます。
@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);
}
ただし、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].
どうすればこの問題を解決できますか? 置き換える@BeforeClass
と@Test
、TestNG の Eclipse プラグインのように Maven で動作します。
maven-surefire-plugin:2.7.2
Eclipse: ヘリオス サービス リリース 1
jdk1.6.0_14
テストNG: 5.14.10