Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
d0cd1df9
Commit
d0cd1df9
authored
Mar 18, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documentation for @IntegrationTest
Fixes gh-499
parent
aca01962
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
howto.adoc
spring-boot-docs/src/main/asciidoc/howto.adoc
+28
-0
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+26
-0
No files found.
spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
d0cd1df9
...
@@ -355,7 +355,35 @@ that and be sure that it has initialized is to add a `@Bean` of type
...
@@ -355,7 +355,35 @@ that and be sure that it has initialized is to add a `@Bean` of type
`ApplicationListener<EmbeddedServletContainerInitializedEvent>` and pull the container
`ApplicationListener<EmbeddedServletContainerInitializedEvent>` and pull the container
out of the event wehen it is published.
out of the event wehen it is published.
A really useful thing to do in is to autowire the
`EmbeddedWebApplicationContext` into a test case and use it to
discover the port that the app is running on. In that way you can use
a test profile that chooses a random port (`server.port=0`) and make
your test suite independent of its environment. Example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleDataJpaApplication.class)
@WebApplication
@IntegrationTest
@ActiveProfiles("test")
public class CityRepositoryIntegrationTests {
@Autowired
EmbeddedWebApplicationContext server;
int port;
@Before
public void init() {
port = server.getEmbeddedServletContainer().getPort();
}
// ...
}
----
[[howto-configure-tomcat]]
[[howto-configure-tomcat]]
=== Configure Tomcat
=== Configure Tomcat
...
...
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
d0cd1df9
...
@@ -1434,6 +1434,32 @@ TIP: The context loader guesses whether you want to test a web application or no
...
@@ -1434,6 +1434,32 @@ TIP: The context loader guesses whether you want to test a web application or no
`MockMVC`) by looking for the `@WebAppConfiguration` annotation. (`MockMVC` and
`MockMVC`) by looking for the `@WebAppConfiguration` annotation. (`MockMVC` and
`@WebAppConfiguration` are part of `spring-test`).
`@WebAppConfiguration` are part of `spring-test`).
If you want a web application to start up and listen on its normal
port, so you can test it with HTTP (e.g. using `RestTemplate`)
annotate your test class (or one of its superclasses)
`@IntegrationTest`. This can be very useful because it means you can
test the full stack of your application, but also inject its
components into the test class and use them to assert the internal
state of the application after an HTTP interaction. Example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleDataJpaApplication.class)
@WebApplication
@IntegrationTest
public class CityRepositoryIntegrationTests {
@Autowired
CityRepository repository;
RestTemplate restTemplate = RestTemplates.get();
// ... interact with the running server
}
----
[[boot-features-test-utilities]]
[[boot-features-test-utilities]]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment