Support fully-qualified factory method names in @⁠TestBean

Prior to this commit, @⁠TestBean factory methods had to be defined in
the test class, one of its superclasses, or in an implemented
interface. However, users may wish to define common factory methods in
external classes that can be shared easily across multiple test classes
simply by referencing an external method via a fully-qualified method
name.

To address that, this commit introduces support for referencing a
@⁠TestBean factory method via its fully-qualified method name following
the syntax <fully-qualified class name>#<method name>.

Closes gh-33125
This commit is contained in:
Sam Brannen
2024-06-30 16:19:13 +02:00
parent c2f8d4803f
commit cc002875c4
5 changed files with 170 additions and 11 deletions

View File

@@ -78,5 +78,12 @@ Java::
<2> The result of this static method will be used as the instance and injected into the field.
======
NOTE: Spring searches for the factory method to invoke in the test class, in the test
class hierarchy, and in the enclosing class hierarchy for a `@Nested` test class.
[NOTE]
====
Spring searches for the factory method to invoke in the test class, in the test class
hierarchy, and in the enclosing class hierarchy for a `@Nested` test class.
Alternatively, a factory method in an external class can be referenced via its
fully-qualified method name following the syntax `<fully-qualified class name>#<method name>`
for example, `methodName = "org.example.TestUtils#createCustomService"`.
====