Skip to content

Introduce AotTestAttributes mechanism in the TestContext framework #29100

Closed
@sbrannen

Description

@sbrannen

Overview

For certain use cases it would be beneficial to be able to compute something during AOT build-time processing and then retrieve the result of that computation during AOT run-time execution.

Use Case

The SpringBootTestContextBootstrapper performs class path scanning for the @SpringBootConfiguration class using a utility called AnnotatedClassFinder; however, class path scanning does not work within a GraalVM native image.

In the Spring Native project, the AnnotatedClassFinder worked without modification because Spring's component indexer was used to index annotated components during the build; however, in Spring Framework 6.0 and Spring Boot 3.0 we do not want to rely on the component indexer.

Ideally, SpringBootTestContextBootstrapper should be able to:

  • Use the AnnotatedClassFinder during AOT build-time processing.
  • Store the class name of the @SpringBootConfiguration class for later retrieval.
  • Retrieve the @SpringBootConfiguration class name that was discovered at build time during AOT run-time execution.

Proposal

Introduce an AotTestAttributes mechanism in the Spring TestContext Framework.

  • conceptually similar to org.springframework.core.AttributeAccessor
  • must allow an AOT-aware component to contribute a key-value pair, where the key is a String and the value is an String
  • initial support should provide convenience methods for retrieving an attribute as a String or boolean
    • if deemed necessary, generic support can later be added for providing a CodeBlock or statement to create the object in the attributes store
  • must generate the necessary source code during the AOT processing phase in the testing framework to create a persistent map of the attributes
  • must provide a mechanism for accessing the stored attributes during AOT run-time execution

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletheme: aotAn issue related to Ahead-of-time processingtype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions