Dopo la cassandra-unit with spring example ho trovato i fagioli di primavera non sono collegati in testclass conseguente eccezioni nullpointer. Ho cercato di minimizzare il problema e l'ho trovato, non è probabilmente la parte Cassandra, ma invece la presenza di una @TestExecutionListeners
annotazione, insieme ad una classe estesa AbstractTestExecutionListener
.TestExecutionListeners annotazione impedisce fagioli primaverili essere cablati in
org.springframework:spring-core:4.2.0.RELEASE (Also fails with 3.2.14.RELEASE).
org.springframework:spring-test:4.2.0.RELEASE
junit.junit:4.11
JVM vendor/version: Java HotSpot(TM) 64-Bit Server VM/1.8.0_40
MAC OS X 10.10.5
mia TestClass assomiglia:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ AppTestListener.class }) <-- OK when removed
@ContextConfiguration(classes = { TestConfiguration.class })
public class MyTest {
@Autowired
private MyService myService;
@Test
public void testMyService() {
Assert.assertNotNull(myService);
Assert.assertEquals("didit", myService.doIt());
}
}
AppTestListener:
public class AppTestListener extends AbstractTestExecutionListener {
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
System.out.println("test");
}
}
Niente di speciale nella classe di configurazione (e fallisce anche per XML di configurazione):
@Configuration
public class TestConfiguration {
@Bean
public MyService myService() {
return new MyService();
}
}
Quando Rimuovo l'annotazione @TestExecutionListeners in MyTest, il test termina come previsto, ma lasciare che l'annotazione renda l'unittest fallito su assertNotNull. Cosa sta succedendo?