Skip to content

Allow @Bean in test classes to override beans loaded via @ContextConfiguration [SPR-7169] #11828

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

Closed
spring-projects-issues opened this issue May 4, 2010 · 5 comments
Labels
in: test Issues in the test module status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

Oliver Drotbohm opened SPR-7169 and commented

It would be cool if test classes executed with SpringJUnit4ClassRunner would be considered as @Configuration classes, too. This way the following would be possible.

@RunWith(SpringJUnitClassRunner.class)
@ContextConfigLocation("classpath:foo.xml")
public class SampleTest {

  @Autowired
  private MyService myService;

  @Bean
  public MyRepository repository() {
    return Mockito.mock(MyRepository.class);
  }

  // Testcases
}

IMHO this has the benefit of not polluting the test resources with zillions of config files that you might want to declare to override certain beans from your default configuration (which you would additionally load inside @ContextConfigLocation). As this co-locates customization needed for the tests and the tests themselves it reduces scattering of artifacts needed for the tests.


Affects: 3.0.2

3 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Interesting idea, Ollie!

@spring-projects-issues spring-projects-issues added in: test Issues in the test module type: enhancement A general enhancement labels Jan 11, 2019
@sbrannen sbrannen self-assigned this Jan 15, 2019
@loganmzz
Copy link

loganmzz commented Jul 10, 2019

Why not use @TestConfiguration ?

@sbrannen
Copy link
Member

Why not use @TestConfiguration?

This issue was raised in 2010 for the core Spring Framework; whereas, @TestConfiguration is a feature specific to Spring Boot.

@loganmzz
Copy link

Good points, I didn't catch it !

@sbrannen sbrannen removed their assignment Dec 22, 2023
@sbrannen
Copy link
Member

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
@sbrannen sbrannen removed this from the General Backlog milestone Dec 22, 2023
@sbrannen sbrannen added the status: superseded An issue that has been superseded by another label Mar 10, 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 status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants