-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support non-default constructors for DisplayNameGenerator
implementations
#3557
Comments
Who would pass the object to the generator's constructor? Why can't you just look up the "test method names" within the default constructor (or some collaborator to which the default constructor delegates)?
There is no "DI framework" per se in JUnit Jupiter. Are you perhaps referring to |
DisplayNameGenerator
implementations
In my case, I use Spring context which manages a bean that provides access to an external system. Let's call it ExternalSystem. Then I would like to inject it through a constructor into the generator class to get test method names in the overridden generator methods. private final ExternalSystem externalSystem;
@Autowired
public ExternalSystemDisplayNameGenerator(ExternalSystem externalSystem) {
this.externalSystem = externalSystem;
}
...
@Override
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {
return externalSystem.getTestName(testMethod);
} |
DisplayNameGenerator
implementationsDisplayNameGenerator
implementations
Team decision: |
It would be nice to be able to pass an object to the generator implementation constructor, which can receive test methods names from an external system.
This object could be used in other parts of the project, or even managed by DI framework context. That is why a constructor is preferable to creating it in a generator class.
The text was updated successfully, but these errors were encountered: