-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement
Milestone
Description
Overview
Currently, @TestBean
factory methods must be defined in the test class or one of its superclasses.
However, users may wish to define common factory methods in interfaces that can be shared easily across multiple test classes simply by implementing the necessary interface(s).
Example
Given the following interface...
interface TestBeanFactory {
public static String createTestMessage() {
return "test";
}
}
... the following should be supported:
@SpringJUnitConfig
public class TestBeanInterfaceIntegrationTests implements TestBeanFactory {
@TestBean(methodName = "createTestMessage")
String message;
@Test
void test() {
assertThat(message).isEqualTo("test");
}
@Configuration
static class Config {
@Bean
String message() {
return "prod";
}
}
}
However, that test class currently fails with an IllegalStateException
because the createTestMessage()
method is not found in the implemented TestBeanFactory
interface.
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement