-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrading from 1.4.0 to 1.4.1 breaks @SpringBootTest's ability to find nested config in abstract base class #7031
Comments
Could be introduced by #6768 though that test looks a bit odd to me. If you want Also
@btiernay Can you please try with |
Yes it does seem related. However adding the following to the base class didn't seem to help: @Test
public void testIgnore() {} |
That's was the previous situation and that was a bug we fixed. Please use |
Adding Note that moving What is the expected behavior in this case? |
@btiernay Does changing your base class to use @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = DEFINED_PORT)
public abstract class BaseIntegrationTest {
@Autowired
protected TestRestTemplate restTemplate;
@TestConfiguration
static class Config {
@Bean
public RestTemplateBuilder restTemplateBuilder() {
return new RestTemplateBuilder()
.requestFactory(SimpleClientHttpRequestFactory.class)
.basicAuthorization("admin", "adminspasswd");
}
}
} |
No, please see referenced project here: https://github.com/btiernay/spring-boot-7031 |
This is only true if the This behaviour is due to The javadoc states that "the returned class array will contain all static nested classes of the supplied class that meet the requirements for @sbrannen Is it intentional that nested configuration classes in a test's super class(es) are not found? |
Yes, this is intentional and perfectly in line with default configuration detection for XML and Groovy config files. In other words, the behavior is consistent. If a user wants configuration to be inherited, the corresponding superclass must be configured to declare the configuration (either implicitly or explicitly). Furthermore, inheritance of configuration can be controlled via the |
Now, having said that, if a superclass is properly configured to use a static nested So if that isn't the case, then that sounds like it might be some sort of bug. |
Thanks, @sbrannen. In this case I believe that the superclass was not properly configured as it made no reference to the nested configuration. With a change to the superclass so that it references its nested configuration class things behave as desired. |
@btiernay As indicated by @sbrannen above, your superclass needs to reference the nested class. You can do so using diff --git a/src/test/java/btiernay/AbstractTest.java b/src/test/java/btiernay/AbstractTest.java
index 83e8ec7..27bd102 100644
--- a/src/test/java/btiernay/AbstractTest.java
+++ b/src/test/java/btiernay/AbstractTest.java
@@ -5,8 +5,10 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
+import btiernay.AbstractTest.Config;
+
@RunWith(SpringRunner.class)
-@SpringBootTest
+@SpringBootTest(classes=Config.class)
public abstract class AbstractTest {
@TestConfiguration The change from 1.4.0 to 1.4.1 aligns Boot's behaviour with Spring's test framework so I think we should keep the new behaviour as that consistency is an improvement. |
In 1.4.0, I had the following working base class for integration tests:
Upon upgrading to 1.4.1 I got exceptions related to not finding the
RestTemplateBuilder
bean:To fix the problem, I needed to explicitly define my config classes :
Has anything changed in the test bean resolution process in 1.4.1 that may have caused this behavior?
The text was updated successfully, but these errors were encountered: