Quarkus Dev Services and Testing

Quarkus Dev Services and Testing

Explains Quarkus Dev Services and testing: zero-config containers, QuarkusTest, integration tests, test resources, RestAssured, mocks, profiles and continuous testing.

Skill files1 file
SKILL.md83 lines
1
---
2
name: quarkus-dev-services-and-testing
3
description: 'Quarkus Dev Services and testing: zero-config containers, @QuarkusTest, @QuarkusIntegrationTest, test resources, RestAssured, @InjectMock, profiles and continuous testing. Use when writing or fixing tests in a Quarkus project.'
4
---
5
6
# Quarkus Dev Services and Testing
7
8
Check the project's Quarkus version first. Framework-neutral Testcontainers usage can use the optional `java-testcontainers` skill if installed (otherwise see <https://java.testcontainers.org/>); this skill covers only Quarkus-specific features.
9
10
## Dev Services
11
12
In dev and test modes Quarkus starts containers (PostgreSQL, MySQL, Kafka, Redis, Keycloak, ...) automatically when the related extension is present and no connection is configured (Docker or Podman required).
13
14
```properties
15
# Global switch
16
quarkus.devservices.enabled=true
17
%dev.quarkus.datasource.devservices.image-name=postgres:17
18
# Reuse container across restarts (also requires testcontainers.reuse.enable=true in ~/.testcontainers.properties)
19
quarkus.datasource.devservices.reuse=true
20
# Fixed port (optional)
21
quarkus.datasource.devservices.port=5432
22
# Share between apps in dev mode
23
quarkus.kafka.devservices.shared=true
24
```
25
26
Disable one with `quarkus.<ext>.devservices.enabled=false`; configuring a URL/host explicitly also disables it. Dev UI (`/q/dev-ui`) lists running services.
27
28
## Tests
29
30
```java
31
@QuarkusTest
32
class GreetingResourceTest {
33
@Test
34
void hello() {
35
given().when().get("/hello").then().statusCode(200).body(is("Hello"));
36
}
37
}
38
```
39
40
Dependencies, test scope: `io.quarkus:quarkus-junit` (3.31+, what the 3.40 template generates) or `quarkus-junit5` (3.27 template; still published and resolvable on 3.40) and `io.rest-assured:rest-assured`. Keep whichever the project already uses.
41
42
- Inject beans in tests with `@Inject`; mock CDI beans with `io.quarkus.test.InjectMock` (`quarkus-junit-mockito`, formerly `quarkus-junit5-mockito`; verified mocking a `PanacheRepository` bean on 3.40.1).
43
- Security: `@TestSecurity(user="alice", roles="admin")` (`quarkus-test-security`).
44
- Profiles: `@TestProfile(MyProfile.class)` with `QuarkusTestProfile#getConfigOverrides()`; restarts the app, so use sparingly.
45
- Transactions: `@TestTransaction` rolls back after the test.
46
- `@QuarkusIntegrationTest` runs against the packaged artifact (jar, native binary or container); you cannot inject beans there, only call it over HTTP.
47
48
## Test resources
49
50
```java
51
public class WireMockResource implements QuarkusTestResourceLifecycleManager {
52
public Map<String,String> start() { /* start, return config overrides */ return Map.of(); }
53
public void stop() { }
54
}
55
56
@QuarkusTest
57
@WithTestResource(WireMockResource.class) // io.quarkus.test.common.WithTestResource
58
class MyTest { }
59
```
60
61
`@WithTestResource` (verified on 3.40.1) applies to the annotated test class; Quarkus restarts the app when the set of resources changes. The older `@QuarkusTestResource` still compiles and runs on 3.40.1 but applies globally to all tests unless `restrictToAnnotatedClass = true`. Do not put `@ConfigProperty` injection points for resource-supplied values in a test class: test classes are scanned as beans, and the app fails to start for other test classes that lack the resource. Prefer Dev Services over custom resources when an extension supports it.
62
63
## Running
64
65
```bash
66
./mvnw test # unit/@QuarkusTest
67
./mvnw verify -DskipITs=false # also runs *IT via maven-failsafe-plugin
68
```
69
70
Gotcha: `*IT` classes (`@QuarkusIntegrationTest`) are run by Failsafe in the `verify` phase, and need the `quarkus-maven-plugin` `build` goal and the failsafe config (with `java.util.logging.manager` and `maven.home` system properties) generated by the project template. `./mvnw test` silently skips them, and the 3.27 and 3.40 templates also set `<skipITs>true</skipITs>`, so plain `./mvnw verify` skips them too (verified): pass `-DskipITs=false` (or `-Dnative`, whose profile flips it). With `-Dnative` and a container build on macOS or Windows, the binary is a Linux ELF and the IT fails with `Exit code is: '126'`; use a local Mandrel/GraalVM build for those.
71
72
Continuous testing: run `./mvnw quarkus:dev` and press `r` to start or re-run tests and `p` to pause them (`h` lists the hotkeys); once running, tests re-run on code changes (`quarkus.test.continuous-testing=enabled|paused|disabled`).
73
74
Verified on Quarkus 3.40.1 (JDK 26, Docker Desktop): `@QuarkusTest` with Dev Services PostgreSQL (`postgres:18` by default), `@TestTransaction`, `@TestProfile`, `@TestSecurity`, `@InjectMock`, `*IT` via Failsafe. `@QuarkusTest` and Dev Services on 3.27.6 as well.
75
76
## Checklist
77
78
- Use Dev Services before writing a custom resource.
79
- Keep `@QuarkusTest` classes sharing the same profile/resources to avoid restarts.
80
- Do not hard-code ports; RestAssured uses `quarkus.http.test-port` automatically.
81
82
See also: <https://quarkus.io/guides/dev-services>, <https://quarkus.io/guides/getting-started-testing>; for upgrades use `quarkus update` (<https://quarkus.io/guides/update-quarkus>).
83

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,337 prompts

More by @OpenSourceBuffGuy

See all
Gold filigree and paper relief fashion figure prompt image

Gold filigree and paper relief fashion figure

Fill-in template for a luxury 3D bas-relief fashion artwork, with material rules for gold filigree, glass, embroidery or papercraft and slots for pose, outfit and lighting.

image-prompt, template, placeholders, papercraft, embroidery, sculpture, luxury, fashion, fashion-shoot, editorial, 3d-render, square-format, text-rendering, illustration, for-artists, for-designers, nano-banana, long-form

Clumsy delivery boy animated comedy short prompt image

Clumsy delivery boy animated comedy short

Describes a Pixar-style 3D animated comedy short in which a clumsy delivery boy causes a chain of slapstick chaos and ends up a hero in a seaside city.

video-prompt, animation, pixar-style, comedy, humorous, short-film, storytelling, camera-movement, tracking-shot, scene-transitions, music-video, widescreen, family-friendly, cozy, vibrant-colors, cartoon, whimsical, cityscape, summer, for-filmmakers, long-form, encouraging, structured-output, 3d-render, text-rendering

Young woman packs gym bag in bedroom prompt image

Young woman packs gym bag in bedroom

Generates a 30-second early-2000s Japanese gym-day vlog in MiniDV camcorder style, with second-by-second beats and a locked character, era and continuity.

video-prompt, vlog, home-video, timed-beats, character-consistency, reference-image, handheld, multi-shot, photorealistic, japan, woman, fitness, guardrails, seedance, candid, long-form, vintage, tracking-shot

Reviews

Loading reviews…

Discussion

Loading comments…