Skip to content

Add @SpringTest annotation to bootstrap integration with the type's lifecycle and features similar to standard Spring components #22924

Closed
@odrotbohm

Description

@odrotbohm

As a follow up of #22286, this ticket is supposed to discuss the idea of a canonical annotation to be used with test classes that constitute Spring integration tests and configure JUnit to treat the class like a Spring component as much as possible. In detail, this includes:

  • The instances of the test class are singletons by default
  • Dependency injection (esp. constructor injection) works just as for Spring components

This could effectively look something like this (name TBD):

@SpringJUnitConfig // Bootstrap Spring container
@AutowireTestConstructor // Enable constructor injection
@TestInstance(Lifecycle.PER_CLASS) // Singleton, i.e. one instance for all test method invocations
// other annotations needed
@interface SpringTest { // SpringTest as that's in line with @SpringBootTest
  // add aliases for attributes of above annotations
}

The goal is to minimalize the conceptual differences between a Spring component in production code and a integration test class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions