Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring-Autowiring happens after @BeforeClass when running test with maven-surefire
    text
    copied!<p>I have some problems with dependency injection (Spring autowiring) and maven-surefire. The following test works without problems when run in eclipse with TestNG: The service-object is injected, then the <code>@BeforeClass</code>-method is called.</p> <pre><code>@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); } </code></pre> <p>However, when I run the very same testcase with maven-surefire, first setup() is called, which causes the test to fail:</p> <pre><code>[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]. </code></pre> <p>How can I solve this problem? If I replace <code>@BeforeClass</code> with <code>@Test</code> it works in maven as in TestNG's eclipse plugin.</p> <p>maven-surefire-plugin:2.7.2</p> <p>Eclipse: Helios Service Release 1</p> <p>jdk1.6.0_14</p> <p>TestNG: 5.14.10</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload