Skip to content

Commit a51739c

Browse files
committed
Integration tests documentation
This commit clarifies how @IntegrationTEST can be used as an alternative of starting the (web) application prior to running the tests suite. Fixes gh-667
1 parent b3022fd commit a51739c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,24 @@ interaction. For Example:
16491649
To change the port you can add environment properties to `@IntegrationTest` as colon- or
16501650
equals-separated name-value pairs, e.g. `@IntegrationTest("server.port:9000")`.
16511651

1652+
As long as you use the same configuration, the context will be cached amongst different
1653+
tests by default. You can therefore use this feature to run a battery of integration tests
1654+
where the server would actually start prior to the tests. In that case, it would be better
1655+
to make sure that your integration tests use a random port for the main server and the
1656+
management one, something like:
16521657

1658+
[source,java,indent=0,subs="verbatim,quotes,attributes"]
1659+
----
1660+
@RunWith(SpringJUnit4ClassRunner.class)
1661+
@SpringApplicationConfiguration(classes = MyApplication.class)
1662+
@WebAppConfiguration
1663+
@IntegrationTest({"server.port=0", "management.port"})
1664+
public class SomeIntegrationTests { ... }
1665+
1666+
----
1667+
1668+
See <<howto-discover-the-http-port-at-runtime>> for a description of how you can discover
1669+
the actual port that was allocated for the duration of the tests.
16531670

16541671
[[boot-features-test-utilities]]
16551672
=== Test utilities

0 commit comments

Comments
 (0)