2

I am having a Spring Boot application with around ~500 Tests (Unit and mostly Integration).

When i start running the tests in IntelliJ with second click -> Run all Tests - tests run in around 10-15mins.

When i try to run the tests with "mvn verify -P itest" in IntelliJ terminal, the execution time is around an hour. This is because this command starts and stops the Spring Test Runner Server on every class (which is not my desired result).

The IntelliJ second click -> Run all Tests starts it only once. Our Jenkins Job is running the tests with "mvn verify -P itest", so my question is how can i change this behavior, to start and stop the Test Runner only once (with this "mvn verify -P itest" command).

itest is the profile that we have in our pom.xml which includes the classes that contain integration tests (using maven failsafe plugin)

Here are the annotations of our base abstract Integration Test class

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MainApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)

I found this article which could by similar to my problem, but this does not explain the behavior that IntelliJ gives me.

Reset Spring-Boot During Integration Tests

Thanks a lot in advance

alext
  • 678
  • 1
  • 11
  • 25
  • The behaviour is defined by your IDE nor by Maven this is based on the kind of tests you have written. Usually you should create less integration tests and more unit tests. This will reduce the testing time... See https://martinfowler.com/articles/practical-test-pyramid.html You should check if you could test things on a lower level of tests to prevent staring up the whole Spring part...which is usually doable. – khmarbaise Jan 05 '19 at 09:51
  • Well obviously this is not correct in my case.Because when running it with my IDE,server runs only once for all,but when running it from Maven, it starts and closes for each class – alext Jan 05 '19 at 10:11

1 Answers1

1

I found out why this was happening. There was a setting in my pom file which stated 'reuseForks' maven failsafe property to be false.

I changed it to be true and now it is working fine.

Intellij works in the same way - it is reusing the forks for all the tests.

Read More

http://maven.apache.org/surefire-archives/surefire-2.17/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html

alext
  • 678
  • 1
  • 11
  • 25