Without going into excruciating detail, I am having an issue when I run my Junit tests all at once. If I run them class by class, everything is great! Otherwise I have trouble because I cannot restart my WebApplication inbetween junit-test-class. This causes me to have Zookeeper server clients in my WebApplication that hang around after I go through the shutdown and startup of the Zookeeper server in-between classes. Those Zookeeper server clients can take a while to resync with server and this causes unpredictable behavior...
Is there a way to have my SpringBootServletInitializer class restart by calling something in the @BeforeClass and @AfterClass methods of a JUnit test?
WebApplication.java
@ComponentScan
@EnableAutoConfiguration
@EnableWebMvc
@EnableHyperMediaSupport(...)
@PropertySources(...)
public class WebApplication extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(WebApplication.class);
}
@Override
protected WebApplicationContext run(SpringApplication application)
{
application.getSources().remove(ErrorPageFilter.class);
return (WebApplicationContext) application.run();
}
public static void main(String[] args)
{
SpringApplication.run(WebApplication.class, args);
}
}
You could use the @DirtiesContext
annotation.
This will hint to the Spring Test runner to reload the context between test methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With