We have some integration tests(written using spring framework) that are failing due to bean initialisation exception which eventually leads to Failed to load ApplicationContext
. As per my understanding from spring testing docs , the loading of ApplicationContext
happens at class level, so my doubt is -
Once the ApplicationContext
fails (i.e. Failed to load ApplicationContext
) due to bean initialisation exception during integration test class run, does the ApplicationContext
try to spin up again(will be failing eventually) for each individual integration tests present in that particular integration test class ?
Failed to load ApplicationContext
) in the integration test class, spring tries to create a new connection to postgres and doesn't destroy it before ApplicationContext
failure. How can we stop this, please help with some suggestions.Also, once we get Failed to load ApplicationContext
, is there a way to programmatically terminate the run of all the integration tests completely automatically ? If yes, please help how to achieve it ?
Thanks.
Testing framework - junit + Spring
Update: Mentioned testing framework used.
UPDATE
I implemented built-in support for a "test context failure threshold" in Spring Framework 6.1 M1.
As of Spring Framework 6.1, a context failure threshold policy is in place which helps avoid repeated attempts to load a failing
ApplicationContext
. By default, the failure threshold is set to1
which means that only one attempt will be made to load anApplicationContext
for a given context cache key. Any subsequent attempt to load theApplicationContext
for the same context cache key will result in an immediateIllegalStateException
with an error message which explains that the attempt was preemptively skipped.
For further details, consult the Spring Framework reference manual.
Original Answer:
There is currently no way to abort integration tests if the ApplicationContext
repeatedly fails to load.
To vote for such support, please see this Spring Framework issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With