I have spring boot app and currently all my test are running green if ai run them separately i.e. manually, but when i run the maven package command then all test run in a serial mode i.e. after each other. What happens then is that i get:
"java.net.BindException: Address already in use".
Basically because the test are running in serial they all try to claim the socket 127.0.0.1:8081. And since the the socket is in a TIME_WAIT state the second test is not able to claim that socket. i.e. the output of netstat -apn
netstat -apn |grep -i 8080
tcp 0 0 127.0.0.1:8080 127.0.0.1:33952 TIME_WAIT
Now i have two different profiles configured i.e. Development and Production i.e. see below:
@Configuration @Profile("Development") public class TomcatEmbededDevelopmentTesting1Profile extends SpringServletContainerInitializer { ... }
@Configuration @Profile("Production") public class TomcatEmbededProductionProfile extends SpringServletContainerInitializer { .. }
What I am looking after now is a feature to specify which customer TomcatServletContainerInitializer i can run i.e. i would have 5 different one all listening on different ports/sockets. The problem is if I have 5 different TomcatEmbeded configuration classes that are all marked with "@Profile("Development")" then how do i tell junit to execute the one that i need. I have tired using the @SpringApplicationConfiguration , but that does not fly.
@SpringApplicationConfiguration(classes = {
...
TomcatEmbededDevelopmentTesting1Profile.class,
...
} )
then i found an article on the net that explains that there is some magic annotation @IntegrationTest("server.port:0") which is suppose to randomize that port, but that did not worked for me as well. What is the right way to do it in spring? Any hints are greatly appreciated.
here is example of my test:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners(listeners={ ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
WithSecurityContextTestExecutionListener.class
}
)
@SpringApplicationConfiguration(classes = {
SecurityWebApplicationInitializerDevelopment.class,
SecurityConfigDevelopment.class,
TomcatEmbededDevelopmentTesting1Profile.class,
Internationalization.class,
MVCConfigDevelopment.class,
PersistenceConfigDevelopment.class,
ServerAuthenticationSuccessHandler.class,
ServerRedirectAuthenticationSuccessHandler.class,
LogicServiceRegistryPostProcessor.class
} )
@WebAppConfiguration
@EnableWebSecurity
@EnableWebSocket
@EnableGlobalMethodSecurity(prePostEnabled = true)
//@IntegrationTest({"server.port=0", "management.port=0"})
@ActiveProfiles("Development")
public class quickTest extends TestCase {
..
}