
How to Use Awaitility for Asynchronous Tests Without Sleeps
Test asynchronous code with Awaitility instead of Thread.sleep: await until a condition holds, tune timeouts and poll intervals, and avoid flaky waits.
Integration tests with real databases, Mockito, Testcontainers and how much of each is worth writing.

Test asynchronous code with Awaitility instead of Thread.sleep: await until a condition holds, tune timeouts and poll intervals, and avoid flaky waits.

Run real PostgreSQL or MySQL in Java tests with Testcontainers: dependencies, JUnit extension, JDBC URL, migrations, performance tips and Docker requirements.

Set timeouts with @Timeout and assertTimeout in JUnit 5, understand threading differences, and handle flaky tests without hiding real bugs through retries.

Cut Testcontainers overhead: static containers, the singleton pattern, Spring context caching, local reuse and cleaning state between tests.

Enforce package and module boundaries in Java with ArchUnit rules and Spring Modulith's verify, so architecture decisions fail the build instead of drifting.

Use SpringBootTest without slow suites: share contexts, avoid DirtiesContext, trim the context, use slices and share containers.

Write parameterized tests in JUnit 5 with ParameterizedTest, ValueSource, NullSource, EnumSource and a display name, and know when a table is clearer.

Test async code and schedulers in Java reliably: Awaitility instead of sleep, injectable executors, fake clocks and Spring Async and Scheduled.

Run JUnit tests only when a condition holds: EnabledOnOs, EnabledForJreRange, EnabledIfEnvironmentVariable, EnabledIf and custom ExecutionCondition.

Test a Micronaut application with MicronautTest, an injected HTTP client, mock beans and Test Resources that start real containers for databases.

Do contract testing with Pact in Java: consumer tests that generate a contract, provider verification, the Pact Broker, can-i-deploy and CI workflow.

Common Java benchmarking mistakes: no warmup, dead code elimination, constant folding, single runs, GC noise, wrong machine and misread averages.
We send one email when a new post is published. No spam.