-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Closed
Description
Inspired by ProjectTester
in Spring Initializr, I'd like us to extend ApplicationContextRunner
to allow registering beans in addition to Configurations
.
Lots of tests are declaring a test @Configuration
class with one or two bean definitions to export additional beans in the context to test. This requires quite a lot of code in the end and a muscle memory to remember what the inner class at the end of the test does.
Consider this:
@Test
public void cacheManagerBackOff() {
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
.run((context) -> assertThat(
getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1"));
}
To be replaced with this proposal by
@Test
public void cacheManagerBackOff() {
this.contextRunner
.withBean(CacheManager.class,
() -> new ConcurrentMapCacheManager("custom1"))
.run((context) -> assertThat(
getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1"));
}
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement