Dev mode, Dev Services and testing
Junior Frequently asked 4 min
On this page
The question
How does live reload work in Quarkus dev mode?
30-second answer
Run quarkus dev, or ./mvnw quarkus:dev. Dev mode watches the sources, and when the next HTTP request arrives after a change, it recompiles what changed, reruns the build steps and restarts the app inside the same JVM (Java Virtual Machine), often in about a second. There is no separate build or redeploy, and changes to configuration are picked up the same way.
Understand it
The dev mode loop
Step by stepRun quarkus dev, or ./mvnw quarkus:dev. The app starts in JVM mode with a debug port and the Dev UI, and dev mode watches your source files.
View as text
Three boxes: your editor, the Quarkus app in dev mode, and a container started by Dev Services. Below them, a console shows what dev mode reports at each step.
Run quarkus dev, or ./mvnw quarkus:dev. The app starts in JVM mode with a debug port and the Dev UI, and dev mode watches your source files.
No datasource URL is set, and Docker is running, so Dev Services starts a PostgreSQL container and passes its URL and credentials to the app.
You edit OrderResource.java and save. Nothing reloads yet: dev mode waits for the next HTTP request, so several saves cost one reload.
The next request finds the change. Quarkus recompiles the class, reruns the build steps and restarts the app in the same JVM, often in about a second.
The database container survives the reload, so its data and URL stay the same. Only the application restarted, and state held in memory is gone.
Press r to turn on continuous testing. After each change, Quarkus reruns in the background only the tests that cover the changed code.
@QuarkusTest starts the app once, on port 8081, and shares it across test classes. With no URL configured, tests get a Dev Services database too.
Three boxes: your editor, the Quarkus app in dev mode, and a container started by Dev Services. Below them, a console shows what dev mode reports at each step.
Run quarkus dev, or ./mvnw quarkus:dev. The app starts in JVM mode with a debug port and the Dev UI, and dev mode watches your source files.
No datasource URL is set, and Docker is running, so Dev Services starts a PostgreSQL container and passes its URL and credentials to the app.
You edit OrderResource.java and save. Nothing reloads yet: dev mode waits for the next HTTP request, so several saves cost one reload.
The next request finds the change. Quarkus recompiles the class, reruns the build steps and restarts the app in the same JVM, often in about a second.
The database container survives the reload, so its data and URL stay the same. Only the application restarted, and state held in memory is gone.
Press r to turn on continuous testing. After each change, Quarkus reruns in the background only the tests that cover the changed code.
@QuarkusTest starts the app once, on port 8081, and shares it across test classes. With no URL configured, tests get a Dev Services database too.
Takeaway: Dev mode reloads changed code on the next request, in the same JVM, while Dev Services keeps a real database running in a container. Tests reuse both.
In code
quarkus dev
# or, without the Quarkus CLI (command-line interface)
./mvnw quarkus:dev# No URL in dev and test, so Dev Services starts PostgreSQL there
quarkus.datasource.db-kind=postgresql
# Production sets a URL, and no container is ever started
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://db:5432/orders
# Turn on continuous testing as soon as dev mode starts
quarkus.test.continuous-testing=enabled@QuarkusTest
class OrderResourceTest {
@InjectMock
PaymentGateway gateway;
@Test
void createsAnOrder() {
given().contentType(ContentType.JSON)
.body("{\"customer\": \"ana\", \"total\": 30}")
.when().post("/orders")
.then().statusCode(201);
Mockito.verify(gateway).charge(new BigDecimal("30"));
}
}Solve it
Dev Services stopped starting the database for tests
After someone added the production database URL to application.properties, mvn test fails with “Connection refused”
on prod-db:5432. Before, tests got a throwaway PostgreSQL from Dev Services. Docker is running. Explain and fix it.
- Recall the trigger. Dev Services starts a container only in dev and test mode, when the extension is present, a container runtime is available and no URL is configured for that datasource.
- Find the configured URL. A key without a profile prefix applies to every profile, including test. The new URL turned Dev Services off and pointed tests at production.
- Scope it. Prefix the key with
%prod.so only production uses it, and keep secrets in environment variables. - Rule out Docker. If the URL were not the cause,
docker infoand the Dev Services log line would show whether a container runtime was found. - Check. The test log shows Dev Services starting PostgreSQL again, and nothing in test reaches
prod-db.
# before: applies to dev, test and prod, so Dev Services stays off
Wrong quarkus.datasource.jdbc.url=jdbc:postgresql://prod-db:5432/orders
# after: production only
Right %prod.quarkus.datasource.jdbc.url=jdbc:postgresql://prod-db:5432/orders
Right %prod.quarkus.datasource.password=${DB_PASSWORD}How to answer
- Reload is lazy, so it runs on the next request, or when you force it from the console.
- Dev mode also opens a debug port, 5005, and the Dev UI at
/q/dev-ui. - Dev Services containers keep running across reloads.
Common mistakes
- Calling it a JVM hot swap. Quarkus restarts the app, so state held in memory is lost.
- Expecting a packaged jar to reload. Only dev mode watches the sources.
Follow-up questions
What are Dev Services, and when do they start?
Dev Services start the infrastructure your extensions need, such as PostgreSQL, Kafka or Keycloak, as containers through Testcontainers, in dev and test modes. One starts only when its extension is present, you have not configured a connection such as a datasource URL, and a container runtime like Docker or Podman is running. Quarkus then passes the URL and credentials to the app.
- Configure a URL and that Dev Service stays off; production never uses Dev Services.
- Containers are kept across live reloads, so data survives a reload.
quarkus.devservices.enabled=falseturns them all off.
What is continuous testing in Quarkus?
In dev mode, press r and Quarkus runs your tests in the background, alongside the running app. After each change, it reruns only the tests that cover the changed code, and shows the results in the console and the Dev UI. You get test feedback seconds after saving, without running Maven.
- It runs the same
@QuarkusTesttests as the build. - Set
quarkus.test.continuous-testing=enabledto start it with dev mode. - It suits a red, green, refactor loop, with no tool switching.
What does @QuarkusTest do, and how is it different from a plain unit test?
@QuarkusTest starts the whole application once, on port 8081 by default, and reuses it for every test class with the same profile. The test class is a CDI (Contexts and Dependency Injection) bean, so it can inject beans, and it calls endpoints over HTTP, often with REST Assured. @InjectMock swaps one bean for a Mockito mock. A plain JUnit test starts nothing and runs in milliseconds.
- A
@TestProfilewith other settings restarts the app, so group tests by profile. @InjectMockworks for normal-scoped beans, such as@ApplicationScoped, not@Singleton.- Dev Services give these tests a real database with no setup.
What is the Dev UI?
A web page at /q/dev-ui, available only in dev mode. Each extension adds a panel, such as the beans ArC found, the configuration with its sources, the Dev Services containers, the REST (Representational State Transfer) endpoints and the test results. You can also change configuration there and see it applied on the next reload.
Check yourself
Show answers
- On the next HTTP request: Correct. Dev mode checks for changes when a request arrives, so several saves cost one reload.
- As soon as the file is saved: Incorrect. Reload is lazy. Nothing happens until a request, or a forced restart.
- Only after you restart dev mode: Incorrect. Avoiding that restart is the point of live reload.
Show answers
- No. A configured URL turns it off.: Correct. Dev Services only fill a gap; your own configuration always wins.
- Yes. It always starts one in dev mode.: Incorrect. It starts one only when no connection is configured.
- Only when the app runs in production: Incorrect. Dev Services never run in production.