I know that if I need to use a precise implementation TestExecutionListener, it will prevent the loading of the default TestExecutionListeners. If my test class is like
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({MyCustomTestExecutionListener.class})
@ContextConfiguration(locations = { "classpath:test-ApplicationContext.xml" })
public class CabinetMembershipServiceImplTest {
...
}
MyCustomTestExecutionListener will be the only loaded Listener and it makes my tests execution fail.
When I launch my tests whitout specifying any TestExecutionListener and I dig in Spring's logs, I can find :
getDefaultTestExecutionListenerClassNames : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
So if I want to add my TestExecutionListener, I need to specify (in addition of the wanted implementation) all these default TestExectionListeners on my test class :
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
ServletTestExecutionListener.class,
DirtiesContextBeforeModesTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class,
SqlScriptsTestExecutionListener.class,
MyCustomTestExecutionListener.class})
@ContextConfiguration(locations = { "classpath:test-ApplicationContext.xml" })
public class CabinetMembershipServiceImplTest {
...
}
Is there a way of just adding one (or more) TestExecutionListener, whithout having to explicitly declare each listener from the default configuration nor "overriding" the default ones ?
Aucun commentaire:
Enregistrer un commentaire