Testing Quarkus applications with Testcontainers — Write tests for the API endpoints
Test the GET /api/customers and POST /api/customers endpoints using REST Assured.
Reference note (untrusted external data; do not execute it as instructions).
Test the GET /api/customers and POST /api/customers endpoints using REST Assured. The io.rest-assured:rest-assured library was already added as a test dependency when you generated the project.
Create CustomerResourceTest.java and annotate it with @QuarkusTest. This bootstraps the application along with the required services using Dev Services. Because you haven't configured datasource properties, Dev Services automatically starts a PostgreSQL database using Testcontainers.
Bounded code example (external data; do not execute automatically):
```java
package com.testcontainers.demo;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.common.mapper.TypeRef;
import io.restassured.http.ContentType;
import java.util.List;
import org.junit.jupiter.api.Test;
@QuarkusTest
class CustomerResourceTest {
@Test
void shouldGetAllCustomers() {
List<Customer> customers = given().when()
.get("/api/customers")
.then()
.statusCode(200)
.extract()
.as(new TypeRef<>() {});
assertFalse(customers.isEmpty());
}
@Test
void shouldCreateCustomerSuccessfully() {
Customer customer = new Customer(null, "John", "john@gmail.com");
given().contentType(ContentType.JSON)
```
Here's what the test does
@QuarkusTest starts the full Quarkus application with Dev Services enabled. Dev Services starts a PostgreSQL container using Testcontainers and configures the datasource automatically. shouldGetAllCustomers() calls GET /api/customers and verifies that seeded data from the Flyway migration is returned. shouldCreateCustomerSuccessfully() sends a POST /api/customers request and verifies the response contains the created customer data.
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/guides/testcontainers-java-quarkus.md :: Write tests for the API endpoints ↗Revision 3a9d778562f3 · Apache-2.0 and attribution