My intention is to enhance configuration of one test among other ones. I am using @TestConfiguration inner class for that specific test. As I understand the flow of how tests are run by SpringRunner the tests are sharing spring context unless some test specify @DirtiesContext annotation. Here is one sample:
public class TestClass {
@TestConfiguration
static class TestConfig {
@Bean
@Primary
public SomeBean testDateTimeProvider() {
return new SomeBean();
}
}
@Autowired
private SomeBean someBean;
}
Curious think is that when I run the set of tests from my IntelliJ IDE, all test pass without problem but from maven (failsafe-plugin) I get an error because in other test, there is this bean exposed from the test above.
Am I assuming correctly, that test share same context unless some of them specifies @DirtiesContext and the problem is that when this test creates SomeBean then other tests will see also it?
By the way, I have solved this situation by removing @TestConfiguration class and importing it directly to test using @Import annotation.
Thank you very much.
Aucun commentaire:
Enregistrer un commentaire