I have some problems with dependency injection (Spring autowiring) and maven-surefire. The following test works without problems when running in eclipse using TestNG: The service object is entered, then the @BeforeClass method is @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); }
However, when I run the same test test with maven-surefire, the first setup () is called, which causes the test to fail:
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ myserver --- [INFO] Surefire report directory: D:\... ------------------------------------------------------- TESTS ------------------------------------------------------- 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].
How can I solve this problem? If I replaced @BeforeClass with @Test , it will work in maven, as in the TestNG eclipse plugin.
Maven-error-free plugin: 2.7.2
Eclipse: Helios Service Release 1
jdk1.6.0_14
TestNG: 5.14.10
java spring spring-test maven testng
thofoer Mar 04 2018-11-11T00: 00Z
source share