Log context cache statistics in the TCF

Prior to this commit, finding out how many application contexts had
been loaded within a test suite required the use of reflection and a
bit of hacking.

This commit addresses this issue by logging ContextCache statistics
whenever an application context is loaded by the Spring TestContext
Framework (TCF).

The log output can be enabled by setting the
"org.springframework.test.context.cache" logging category to DEBUG.

Issue: SPR-12409
This commit is contained in:
Sam Brannen
2014-11-03 15:16:44 +01:00
parent 8b5fda5ad9
commit da04362a5e
4 changed files with 31 additions and 29 deletions

View File

@@ -20851,6 +20851,12 @@ framework will not be able to cache application contexts between test classes an
build process will run significantly slower as a result.
====
Since having a large number of application contexts loaded within a given test suite can
cause the suite to take an unnecessarily long time to execute, it is often beneficial to
know exactly how many contexts have been loaded and cached. To view the statistics for
the underlying context cache, simply set the log level for the
`org.springframework.test.context.cache` logging category to `DEBUG`.
In the unlikely case that a test corrupts the application context and requires reloading
-- for example, by modifying a bean definition or the state of an application object --
you can annotate your test class or test method with `@DirtiesContext` (see the
@@ -20860,6 +20866,7 @@ context before executing the next test. Note that support for the `@DirtiesConte
annotation is provided by the `DirtiesContextTestExecutionListener` which is enabled by
default.
[[testcontext-ctx-management-ctx-hierarchies]]
====== Context hierarchies