Po stwierdzeniu, że fasola szparagowa nie jest podłączona do klasy testowej, powodując wyjątki nullpointer. Próbowałem zminimalizować problem i stwierdziłem, że prawdopodobnie nie jest to część Cassandra, ale zamiast tego obecność adnotacji @TestExecutionListeners
wraz z rozszerzoną klasą AbstractTestExecutionListener
.Adnotacja TestExecutionListeners zapobiega zbrojeniu fasoli sprężystej w
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
mój TestClass wygląda następująco:
@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");
}
}
Nic specjalnego w klasie konfiguracji (i to również nie do xml konfiguracji):
@Configuration
public class TestConfiguration {
@Bean
public MyService myService() {
return new MyService();
}
}
Kiedy Usuwam adnotację @TestExecutionListeners w MyTest, ponieważ test kończy się zgodnie z oczekiwaniami, ale pozostawienie tej adnotacji powoduje niepowodzenie unieważniania na assertNotNull. Co się dzieje?