[go: nahoru, domu]

Skip to content
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 @TestBean factory methods defined in interfaces #32943

Closed
sbrannen opened this issue Jun 3, 2024 · 0 comments
Closed

Support @TestBean factory methods defined in interfaces #32943

sbrannen opened this issue Jun 3, 2024 · 0 comments
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member
sbrannen commented Jun 3, 2024

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.

@sbrannen sbrannen added in: test Issues in the test module type: enhancement A general enhancement labels Jun 3, 2024
@sbrannen sbrannen added this to the 6.2.0-M4 milestone Jun 3, 2024
@sbrannen sbrannen self-assigned this Jun 3, 2024
sbrannen added a commit that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant