Home > Back-end >  @QuarkusTest unit tests take a long time
@QuarkusTest unit tests take a long time

Time:09-24

I started a project and have about 7 tests in my project now and it takes already more than a minute to execute the whole test suite using gradle test.

From the additional output (--info flag) I can see that the whole quarkus application and also dependencies like the mongodb instance are restarted for every test class and method.

This is the exact opposite of what the quarkus documentation says on the testing guide page:

So far in all our examples we only start Quarkus once for all tests. Before the first test is run Quarkus will boot, then all tests will run, then Quarkus will shutdown at the end. This makes for a very fast testing experience however it is a bit limited as you can’t test different configurations.

All the tests are annotated with @QuarkusTest and every test just tests a single endpoint.

I use "pure" kotlin (1.5.21), Quarkus version 2.2.2.Final and gradle 6.9. Installed features: cdi, config-yaml, jacoco, kotlin, mongodb-client, mongodb-panache-kotlin, narayana-jta, rest-client, rest-client-jackson, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-health, smallrye-openapi, swagger-ui

Is that a normal behaviour? If yes, an application with multiple hundred tests could easily take ~20 minutes or more to run the entire test suite.

I didn't try out maven yet, so I can't verify that it's not a gradle related issue.

CodePudding user response:

While trying to reproduce it with a fresh project, I think I found the issue with my code: I also used @QuarkusTestResources with restrictToAnnotatedClass=true on my tests. This means the configuration & test profiles must be reloaded and therefore also the quarkus application. Apparently all the DevServices get restarted, too (in my case it was a mongodb, since I'm using the panache extension), which explains the long runtimes of the tests.

I reorganized my tests a little bit, so they work with the "global" test resources (it was a WireMockServer in my case). Now quarkus only gets started once before the tests and the total runtime of the gradle test task is acceptable.

  • Related