Revise convention-based semantics for @TestBean
factory methods
#32940
Labels
Milestone
@TestBean
factory methods
#32940
Uh oh!
There was an error while loading. Please reload this page.
Overview
If the name of the test bean factory method is not explicitly configured in the
@TestBean
annotation, a convention-based lookup of the corresponding test bean factory method is performed according to the following semantics.However, I assume that many users will likely not wish to be forced to use the
TestOverride
suffix.Instead, we should provide greater flexibility in the convention-based approach.
Example
With the status quo, the following example only passes if the factory method is named exactly
exampleServiceTestOverride
.Proposal
To align with the naming conventions used for
@Bean
in Spring as well as@MethodSource
and@FieldSource
in JUnit Jupiter, I propose that we allow test bean factory methods to carry the same name as the annotated@TestBean
field by default.For example, the above test class should pass if we rename the
exampleServiceTestOverride()
method toexampleService()
as follows.Options for Consideration
I think we should go with option 1 in any case, and we should consider option 2.
The rationale for removing support for the
TestOverride
suffix is that the naming is arbitrary and potentially undesired by users.TestBean
to align with the@TestBean
feature's name, or they might think some other suffix would be more suitable. In other words, it will impossible to please all users with a predefined suffix.methodName
attribute to avoid use of that suffix.methodName
attribute as they see fit, and if they do, I doubt that many users would choose to use aTestOverride
suffix.Prototype
Implementing support for the above Proposal (consideration option 1) is as simple as adding the following line to
TestBeanOverrideProcessor.createMetadata(...)
.The text was updated successfully, but these errors were encountered: