FIXIT: Unit Test PullRequestControllerTest fails due to ApplicationContext bootstrap error (SZ-35)
rk@tigase.net opened 1 week ago

Description

PullRequestControllerTest consistently fails to initialize the Spring ApplicationContext during test startup with the following exception:

java.lang.IllegalStateException: ApplicationContext failure threshold (1) exceeded:
skipping repeated attempt to load context for [WebMergedContextConfiguration...]

The error occurs before any controller logic executes.
Stack traces show the test context being loaded via:

contextLoader = org.springframework.boot.test.context.SpringBootContextLoader
propertySourceProperties = ["org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper=true"]

This indicates that @WebMvcTest is not using its intended lightweight slice loader but instead triggering a full Spring Boot application context, causing initialization failure.


Observed Behavior

  • All controller tests in PullRequestControllerTest fail with identical context load errors.
  • The root cause appears tied to a rogue property (WebMvcTestContextBootstrapper=true) that forces the wrong ContextLoader.
  • The failure happens before any MockMvc interaction.
  • Disabling the test allows the rest of the suite to pass cleanly.

Expected Behavior

@WebMvcTest(PullRequestController.class) should initialize a minimal web slice context with:

  • MockMvc
  • The target controller
  • Mocked service beans
  • Imported GlobalExceptionHandler

and should not attempt to start the full Spring Boot application context.


Impact

  • Affects: PullRequestControllerTest only
  • Other controller and service tests remain unaffected
  • Prevents validation of REST endpoint behavior and exception handling

Temporary Workaround

Disable the entire test class:

@Disabled("FIXIT: ApplicationContext bootstrap failure – tracked under SZ-XX")

This preserves suite stability while the root cause is investigated.


Next Steps

  1. Investigate the source of "WebMvcTestContextBootstrapper=true".
  2. Verify that no @TestPropertySource or external configuration injects internal Boot flags.
  3. Confirm that @WebMvcTest defaults to the proper loader (AnnotationConfigContextLoader).
  4. Re-enable the test once the correct lightweight slice behavior is restored.

Estimate: 2h
Priority: Medium
Status: OPEN
Assignee: Rk
File: backend/src/test/java/com/sztab/controller/PullRequestControllerTest.java

  • rk@tigase.net changed fields 1 week ago
    Name Previous Value Current Value
    Type
    New Feature
    Bug
  • rk@tigase.net commented 1 week ago

    Amended code:

    @Disabled("FIXIT SZ-35: ApplicationContext bootstrap failure – see issue SZ-35")
    @WebMvcTest(controllers = PullRequestController.class)
    @AutoConfigureMockMvc(addFilters = false)
    @Import(GlobalExceptionHandler.class)
    @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
    class PullRequestControllerTest {
    ...
    }
    
  • rk@tigase.net referenced from other issue 1 week ago
issue 1 of 1
Type
Bug
Priority
Normal
Assignee
Version
1.0
Sprints
n/a
Customer
n/a
Issue Votes (0)
Watchers (3)
Reference
SZ-35
Please wait...
Page is in error, reload to recover