-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Investigate convention based application.properties specifically for tests #38098
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
Comments
I played around a bit and came up with this solution: https://github.com/mhalbritter/spring-boot/tree/mh/38098-investigate-convention-based-applicationproperties-specifically-for-tests It adds a new That way users can use an WDYT? |
I think a more generic approach could be applied here instead of using For example: @ActiveProfiles
public @interface SpringBootTest {
/**
* The profiles to activate.
* @return profiles to activate.
* @since 3.5.0
*/
@AliasFor(annotation = ActiveProfiles.class)
String[] profiles() default { "test" };
}
@SpringBootTest(profiles = {}) // no profiles
@SpringBootTest // 'test' profile
@SpringBootTest( profiles = { "profile1", "profile2" }) // 'profile1' and 'profile2' The same idea could be applied to slice annotations such as But it looks like it does not work with
|
@SpringBootTest(profiles = "test1")
@ActiveProfiles("test2")
class MyTests { /* ... */ } When you declare Please note that However, |
Thanks, @sbrannen In that case, private String[] getActiveProfiles(Class<?> testClass, String[] activeProfiles) {
SpringBootTest annotation = getAnnotation(testClass);
Set<String> profiles = new LinkedHashSet<>(Arrays.asList(activeProfiles));
if (annotation != null) {
profiles.addAll(Arrays.asList(annotation.profiles()));
}
return profiles.toArray(String[]::new);
} |
I wonder if we should keep #24688 in mind when looking at this. If you squint a bit, tests could be thought of as an extra "module" that adds to the application's usual properties. |
In my library (see docs), I provide two profiles out-of-the-box that are enabled when running the application in development mode ( To achieve this, I relied on an The library is included in a project only for development and test, so there is no risk to include dev/test config in the final production artefact. For example, in Gradle: dependencies {
testAndDevelopmentOnly 'io.arconia:arconia-dev-tools'
} Furthermore, the whole feature can be turned off via properties. |
Currently it can can be quite awkward to add an
application.properties
for tests that overrides only specific values of the one insrc/main/java
. Some folks resort to adding a profile specific property and enabling a profile in all their tests. Some mix.properties
and.yaml
so that both files load and some useimport:
.It would be nice if we had an out-of-the-box solution.
In addition, we could try to address the concern mentioned in #5307 (comment) and provide a way for a global user specific test
application.properties
file to also be loaded.The text was updated successfully, but these errors were encountered: