Spring Boot + bqemulator (Testcontainers)¶
A minimal Spring Boot service whose CustomerRepository talks to
BigQuery via google-cloud-bigquery. The integration test starts
bqemulator via Testcontainers and asserts the round-trip.
What it demonstrates¶
- A Spring
@Configurationthat constructsBigQueryOptionswith a conditionalsetHost(...)override driven by thebqemulator.endpointproperty. - Using
NoCredentials.getInstance()for the emulator path so no real GCP credentials are needed. - A JUnit 5 integration test that:
- Starts the
ghcr.io/jjviscomi/bqemulator:devimage via the Testcontainers Java client. - Sets
BIGQUERY_EMULATOR_HOSTvia@DynamicPropertySourcebefore the Spring context starts. - Seeds a small dataset and verifies the repository returns the expected rows.
Layout¶
pom.xml
src/main/java/com/example/bqemu/
BqemuApplication.java
BigQueryConfig.java
CustomerRepository.java
src/main/resources/application.properties
src/test/java/com/example/bqemu/
CustomerRepositoryIT.java
Run¶
make test runs mvn -B verify, which executes the Testcontainers-
driven integration tests. Requires Docker to be running.
What to look for¶
- Production wiring (no
bqemulator.endpoint) uses ADC and the public BigQuery host — same code path as a real deployment. - Test wiring (Testcontainers) sets
bqemulator.endpointso theBigQueryOptionsbuilder callssetHost(...). This is the recommended idiom for swapping endpoints in Spring Boot.