Reputation: 3883
The unit test template of jhipster is great, but sometime, especially, during coding, I need to write unit test code and run frequently. But now the unit test will start tomcat container and many other module, which I don't need if I want to test a service function.
Now the test class is like this:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
@Transactional
public class SomeClassTest {
.....
How can I modify it to only initialize spring container and DB? Thanks.
Upvotes: 1
Views: 1973
Reputation: 33091
If you do not need the server, don't make your test an integration test. If you remove @WebAppConfiguration
and @IntegrationTest
spring boot will start a regular (i.e. non-web context) and will not start Tomcat.
If you need to go even further, you can disable certain features, either via application-test.properties
+ @ActiveProfiles("test")
to disable stuff via config or using the exclude
parameter of @SpringBootApplication
(or @EnableAutoConfiguration
) as Lukas said already.
Upvotes: 2
Reputation: 1860
Take a look at this question How to exclude *AutoConfiguration classes in Spring Boot JUnit tests? and see if this helps you. The idea is to explicitly exclude auto configurations that you don't need in your test, so in your case it would probably be EmbeddedServletContainerAutoConfiguration
Upvotes: 0