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 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.

Step 1 of 7
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.

When does Dev Services start a container?Dev Services starts a container only in dev or test mode, when no connection is configured and a container runtime is running. A configured URL, a missing runtime, or production mode means no container.Dev Services fora datasourceDev or test, no URL,Docker up: start oneURL configured:no containerNo containerruntime:nothing startsProduction:never
When does Dev Services start a container?Dev Services starts a container only in dev or test mode, when no connection is configured and a container runtime is running. A configured URL, a missing runtime, or production mode means no container.Dev Services fora datasourceDev or test, no URL,Docker up: start oneURL configured:no containerNo containerruntime:nothing startsProduction:never
When does Dev Services start a container?

In code

quarkus dev
# or, without the Quarkus CLI (command-line interface)
./mvnw quarkus:dev
Start dev mode
# 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
Dev Services in dev and test, a real URL in production
@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"));
    }
}
A @QuarkusTest: the real app, one bean mocked
From a saved file to the new code runningYou save OrderResource.java. The next request makes dev mode recompile and rerun the build steps, restart the app in the same JVM, and answer with the new code, while the database container keeps running.SaveOrderResource.javaNext request:GET /ordersRecompile, rerunthe build stepsRestart the appin the same JVMAnswer with the newcode; container kept
From a saved file to the new code runningYou save OrderResource.java. The next request makes dev mode recompile and rerun the build steps, restart the app in the same JVM, and answer with the new code, while the database container keeps running.SaveOrderResource.javaNext request:GET /ordersRecompile, rerunthe build stepsRestart the appin the same JVMAnswer with the newcode; container kept
From a saved file to the new code running

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.

  1. 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.
  2. 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.
  3. Scope it. Prefix the key with %prod. so only production uses it, and keep secrets in environment variables.
  4. Rule out Docker. If the URL were not the cause, docker info and the Dev Services log line would show whether a container runtime was found.
  5. 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}
Only production sets a URL; dev and test get Dev Services

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=false turns them all off.

See it in the infographic: The dev mode loop

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 @QuarkusTest tests as the build.
  • Set quarkus.test.continuous-testing=enabled to start it with dev mode.
  • It suits a red, green, refactor loop, with no tool switching.

See it in the infographic: The dev mode loop

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 @TestProfile with other settings restarts the app, so group tests by profile.
  • @InjectMock works for normal-scoped beans, such as @ApplicationScoped, not @Singleton.
  • Dev Services give these tests a real database with no setup.

See it in the infographic: The dev mode loop

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

1. You save a change while quarkus dev runs, and then wait without sending any request. When does the app reload?
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.
2. Your dev profile sets quarkus.datasource.jdbc.url. Does Dev Services start a database container in dev mode?
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.