Affects: 5.2.2.RELEASE


When using JUnit Jupiter and the SpringExtension I want to configure it to be able to use constructor injection without putting @Autowired on each parameter. This is supported if I set spring.test.constructor.autowire.mode=all in a file named spring.properties or set matching system property.

However I'm familiar with configuring how junit runs globally among tests by setting properties in the junit-platform.properties file.

Could we add that as an additional lookup for that property to unify this configuration?

Comment From: checketts

FYI @sbrannen

Comment From: sbrannen

Could we add that as an additional lookup for that property to unify this configuration?

That would certainly be possible, and I considered that originally but wasn't sure if people would actually want that as an option.

So, now that you've brought it up, I suppose at least one Spring user would like that feature. 😉

There are two challenges involved.

  1. The @TestConstructor support is generic by design -- even if it is currently only supported in conjunction with JUnit Jupiter. Thus, we'd have to make the lookup possible without a direct dependency on JUnit Jupiter's ExtensionContext API. That can likely be solved via a Supplier<String> argument in TestConstructorUtils for an externally sourced properties file lookup.
  2. Which source should take precedence -- spring.properties or junit-platform.properties? I tend to think spring.properties should take precedence, only using the externally sourced lookup as a fallback.

Comment From: sbrannen

Current work on this issue can be viewed here: https://github.com/spring-projects/spring-framework/compare/master...sbrannen:issues/gh-24285-test-constructor-junit-config-param