You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have liquibase in the classpath, and spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration in the application.yml file, Liquibase autoconfiguration is indeed excluded when running the app, but not when executing tests annotated with @DataJpaTest.
I would have expected the exclusion to be also applicable to the tests.
The workaround is trivial: use @DataJpaTest(excludeAutoConfiguration = LiquibaseAutoConfiguration.class)
I guess that this bug could also exist for other autoconfigurations and/or other test annotations, and that changing the behavior might break lots of existing tests. So maybe the solution could simply be to better document this spring.autoconfigure.exclude property, warn that it's ignored in tests, and explain how to work around it (since it's quite easy).
The text was updated successfully, but these errors were encountered:
wilkinsona
changed the title
Property spring.autoconfigure.exclude ignored by DataJpaTest
Property spring.autoconfigure.exclude ignored by test slices
Jun 17, 2020
wilkinsona
changed the title
Property spring.autoconfigure.exclude ignored by test slices
Property spring.autoconfigure.exclude ignored by test slices
Jun 17, 2020
Unfortunately, this is more complicated than we had realised. ImportAutoConfigurationImportSelector implements DeterminableImports which is implemented by a selector that can determine its imports early. This early determination is done before the environment has been set via EnvironmentAware. This means that the spring.autoconfigure.exclude property can't be considered and, therefore, early determination of the imports isn't possible if we want to honour that property. The imports that are determined are part of the cache key that's used by the test framework so I don't think resolving this is as simple as no longer implementing DeterminableImports.
If I have liquibase in the classpath, and
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
in theapplication.yml
file, Liquibase autoconfiguration is indeed excluded when running the app, but not when executing tests annotated with@DataJpaTest
.I would have expected the exclusion to be also applicable to the tests.
The workaround is trivial: use
@DataJpaTest(excludeAutoConfiguration = LiquibaseAutoConfiguration.class)
I guess that this bug could also exist for other autoconfigurations and/or other test annotations, and that changing the behavior might break lots of existing tests. So maybe the solution could simply be to better document this
spring.autoconfigure.exclude
property, warn that it's ignored in tests, and explain how to work around it (since it's quite easy).The text was updated successfully, but these errors were encountered: