Clarify behavior of JMX in @SpringBootTest

Closes gh-13008
This commit is contained in:
Stephane Nicoll
2018-05-03 11:06:55 +02:00
parent dd3f57d816
commit 830e523531
3 changed files with 102 additions and 7 deletions

View File

@@ -5363,7 +5363,13 @@ features of Spring Boot are only installed in the context by default if you use
Spring Boot provides a `@SpringBootTest` annotation which can be used as an
alternative to the standard `spring-test` `@ContextConfiguration` annotation when you need
Spring Boot features. The annotation works by creating the `ApplicationContext` used
in your tests via `SpringApplication`.
in your tests via `SpringApplication`. In addition to `@SpringBootTest` a number of other
annotations are also provided for
<<boot-features-testing-spring-boot-applications-testing-autoconfigured-tests,testing more
specific slices>> of an application.
TIP: Don't forget to also add `@RunWith(SpringRunner.class)` to your test, otherwise
the annotations will be ignored.
You can use the `webEnvironment` attribute of `@SpringBootTest` to further refine
how your tests will run:
@@ -5388,12 +5394,6 @@ or `DEFINED_PORT` implicitly provides a real servlet environment, HTTP client an
server will run in separate threads, thus separate transactions. Any transaction
initiated on the server won't rollback in this case.
NOTE: In addition to `@SpringBootTest` a number of other annotations are also
provided for testing more specific slices of an application. See below for details.
TIP: Don't forget to also add `@RunWith(SpringRunner.class)` to your test, otherwise
the annotations will be ignored.
[[boot-features-testing-spring-boot-applications-detecting-config]]
@@ -5482,6 +5482,19 @@ include::{code-examples}/test/web/RandomPortExampleTests.java[tag=test-random-po
[[boot-features-testing-spring-boot-applications-jmx]]
==== Using JMX
As the test context framework caches context, JMX is disabled by default to prevent
identical components to register on the same domain. If such test needs access to an
`MBeanServer`, consider marking it dirty as well:
[source,java,indent=0]
----
include::{test-examples}/jmx/SampleJmxTests.java[tag=test]
----
[[boot-features-testing-spring-boot-applications-mocking-beans]]
==== Mocking and spying beans
It's sometimes necessary to mock certain components within your application context when