I'm trying to run an integration test that has a different SpringApplicationConfiguration
from the other integration tests. The issue only manifests when Gemfire is configured.
A demonstration of the error in available here: https://github.com/kemitix/test-spring-boot-gemfire-testing
There are two test classes ContextsApplicationTests
and ContextsApplicationWithCustomTests
.
The first uses a standard SpringApplicationConfiguration
based on the ContextsApplication
class. The other attempts to also include the CustomConfiguration
class to override a Bean.
Test one:
@IntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ContextsApplication.class)
public class ContextsApplicationTests {
...
Test two:
@IntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {
ContextsApplication.class,
CustomConfiguration.class
})
public class ContextsApplicationWithCustomTests {
Without having Gemfire enabled the tests run happily.
However, having Gemfire configured causes an issue with the context loader throwing an IllegalArgumentException
:
Caused by: java.lang.IllegalArgumentException:
a beanFactoryReference already exists for key cacheFactoryBean
The full output is included in the file mvn-clean-install.txt
in the repo.
When the two tests are run in isolation they work. It is only when they are run together that the issue appears. I suspect the Gemfire instance that Spring Boot is running is causing some sort of bleed-over between the two tests that is causing the Contexts not to be properly segregated. Unfortunately, I've no idea how to influence this.
@DirtiesContext
to theContextsApplicationWithCustomTests
class. However, in my use-case that configuration applies to all but one test. The exception is the test that doesn't use theCustomConfiguration
. Using@DirtiesContext
onContextsApplicationTests
doesn't resolve the issue. – Paul Campbell