-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
If I set the management port via configuration then a Tomcat will be started listening on that port when running @WebAppConfiguration
tests.
I.e. an application.yml
with:
management:
port: 8081
would cause a Tomcat to start on port 8081 when running a test looking like this:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringApplicationConfiguration(classes = {Application.class})
public class ATest {
...
}
This is not the intended behavior if I am correct or am I missing something?
The implication I am running into (this might be a separate issue) is that if I have two tests with different application contexts then that will cause the second test to fail. Apparently because the loading of the second application context also tries to start a Tomcat on the same port. Which obviously fails.
That is, if the second test looks like:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringApplicationConfiguration(classes = {Application.class, BTest.Conf.class})
public class BTest {
...
}
then running both ATest
and BTest
will fail one of them.
So I guess the two questions are
- Is a Tomcat for the management port supposed to start in the test?
- If so, why is the second application context triggering a start of a new Tomcat?
I put some example code that illustrates this here https://github.com/sawano/spring-boot-management-port-test-issue