spring-projects / spring-projects/spring-framework

Allow `TestContextBootstrapper` to be configured globally without `@BootstrapWith`

Open
#34,879 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: test status: feedback-provided status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

I find myself needing to customize the ContextCache so that I can run tests in parallel JUnit. Yes can be done with @BootstrapWith, but it is quite burdensome to have to add this so every single test class. This is fine for a handful of classes, but not feasible with over 100 test classes.

I have worked out how to create separate Postgres databases for each application context that loads with an ApplicationContextInitializer, which can be done globally with spring.factories, but as far as I can tell, the TestContextBootstrapper can only be overridden at the class level.

I cannot use @DirtiesContext because again, I would have to annotate every class, and this is causing my Hikari pool to get closed.

In summary, it would be much appropriated to be able to customize ContextCache globally for all tests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading TestContextBootstrapper and the existing @BootstrapWith configuration path to understand how bootstrapper selection is currently scoped. Define how a global configuration would be discovered and applied, then add coverage showing that the selected bootstrapper affects all applicable test classes without per-class annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.