Skip to content

Unique Spring test contexts still boot a full application #315

Closed

Description

@fjlopez

What is wrong

The 2026-10-21 H2 run spent about 211s between JUnit suite timestamps. That gap is context startup (maxParallelForks = 1). These classes each force a context the shared @SpringBootTest + @AutoConfigureMockMvc cache cannot reuse. Suite method time for each one is under a second.

Class Mechanism Gap before the suite
ResetPasswordControllerTest Profiles.MAIL and @Import(MockMailConfig.class) 16.43s
TemplateMoreInfoAdvancedRenderSecurityTest @MockitoBean TemplateExecutionService 15.79s
UserPositionRepositoryDataRestTest @AutoConfigureWebMvc and @AutoConfigureTestDatabase(NONE) while the other Data REST tests use @AutoConfigureMockMvc 14.73s
JsonWebTokenServiceTest @AdditiveActiveProfiles(Profiles.TEST) and @Import(FixedClockConfig.class). The tests call JsonWebTokenService only 13.91s
SpatialReferenceSystemTest extends BaseTest and @MockitoBean CodeListValueRepository 12.01s
UserChecksServiceTest @SpringBootTest plus mocked repositories, then userChecksService.getWarnings 11.30s
UserPositionBusinessLogicTest nested @Import of the business-logic class 6.16s
DefaultLanguageChangeControllerTest extends BaseTest and @MockitoBean DefaultLanguageChangeService 4.93s
TaskLiteralEnrollmentDataRestTest @MockitoSpyBean LiteralTranslationEnsureService 4.83s
DatabaseConnectionControllerTest extends BaseTest and @MockitoBean DatabaseConnectionRepository 4.67s

CodeListTest is the same shape as SpatialReferenceSystemTest and paid 10.17s. Leave it on BaseTest.

Why this is not a test-only edit

A @WebMvcTest or plain unit move changes which beans and filters run. The mock, profile, or spy is the cache key and also the behavior under test. TaskLiteralEnrollmentDataRestTest needs the spy to throw on one method and the real enroll path on the other.

Done when

Each class either shares an existing context or documents why its context must stay unique. A wrong observable result still fails the test.

Activity

  1. added
    plannedActive backlog; exempt from stale bot
    on Oct 21, 2026
  2. added theissue type on Oct 21, 2026
  3. fjlopez commented on Oct 21, 2026

    @fjlopez
    ContributorAuthor

    A later H2 run on the same day, 08:04:19Z to 08:06:49Z, measured these gaps again after the empty i18n nested configurations were hoisted. Method time for the ten classes is still under a second. The gaps are smaller than the 211s total in the issue, and these classes still do not share the warm BaseTest context.

    CodeListTest (5.00s) and SpatialReferenceSystemTest (6.12s) extend BaseTest and add @MockitoBean CodeListValueRepository. The field names differ (codeListValueRepository and repository), so they are two cache keys. HttpURLTest, MinMaxTest, and BoundingBoxTest reuse BaseTest at about 0s.

    The seed already has the answers those stubs force. STM_CODELIST.csv legend types are LINK, LEGENDGRAPHIC, and CAPABILITIES, so WRONG VALUE is absent. service.type includes WMS. @Srs checks the EPSG: pattern in SrsSystemListValidator, not the code list. Dropping the mock keeps both classes on BaseTest. That is not a @WebMvcTest move. CodeListTest staying on BaseTest still holds.

    The other classes in this issue still need the mock, profile, or spy that the assertion reads. Do not fold them into this comment's smaller edit.

  4. fjlopez commented on Oct 21, 2026

    @fjlopez
    ContributorAuthor

    The working tree removes @DirtiesContext from UserPositionBusinessLogicTest and UserPositionRepositoryDataRestTest. Both classes still have the cache key named in this issue. CodeListTest still has @MockitoBean CodeListValueRepository. The pass method that expected no $.errors[?(@.property)] match is gone. The remaining method still stubs that repository, so the 5.00s gap is unchanged by that deletion.

  5. fjlopez commented on Oct 22, 2026

    @fjlopez
    ContributorAuthor

    Fixed on dev by #351.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plannedActive backlog; exempt from stale bot

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions