1

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.

Mavlarn
  • 3,807
  • 2
  • 37
  • 57

2 Answers2

2

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.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
0

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

Community
  • 1
  • 1
Lukas Hinsch
  • 1,840
  • 14
  • 8