Skip to content

Clarify scope of "@SpringBootTest#classes" #18229

@ttddyy

Description

@ttddyy

I found this test passes:

@SpringBootTest(classes = RestTemplate.class)
class MyTest {

    @Autowired
    RestTemplate restTemplate;

    @Test
    void check() {
        assertThat(restTemplate).isNotNull();
    }
}

The underlying reason is same as what I reported here: spring-projects/spring-framework#23638

Since spring-boot is more opinionated, I think it makes sense to restrict @SpringBootTest#classes for only @Configuration classes.

SpringBootTestContextBootstrapper may filter out non @Configuration classes or throw exception when it constructs MergedContextConfiguration.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions