Catalog
concept#Quality Assurance#Software Engineering#DevOps#Observability

Java Testing

Concept and collection of practices for testing Java applications across unit, integration, and end-to-end tests.

Java testing covers methods and practices for designing, executing, and automating tests for Java applications.
Established
Medium

Classification

  • Medium
  • Technical
  • Design
  • Intermediate

Technical context

JUnit / MockitoTestcontainers / DockerCI systems (Jenkins, GitHub Actions, GitLab CI)

Principles & goals

Tests should be fast, deterministic, and maintainable.Test pyramid prioritizes unit tests, then integration, then E2E.Automation and CI integration are prerequisites for fast feedback.
Build
Team, Domain

Use cases & scenarios

Compromises

  • Tests too tightly coupled to implementation
  • Blind trust in tests without code reviews
  • Insufficient test data quality leads to false confidence
  • Keep tests small, fast and deterministic.
  • Provide consistent and reproducible test data.
  • Keep CI feedback loops short and fix flaky tests.

I/O & resources

  • Source code and tests
  • CI/CD pipeline
  • Test data and mocks
  • Test reports
  • Bug tickets with reproducible steps
  • Quality metrics (coverage, runtimes)

Description

Java testing covers methods and practices for designing, executing, and automating tests for Java applications. It includes unit, integration, and end-to-end tests, along with test frameworks, mocking, and test data strategies. Best practices and CI-based automation provide fast feedback and help detect regressions early.

  • Early bug detection reduces the cost of fixes
  • Fast feedback increases developer productivity
  • Automated tests guard against regressions

  • High maintenance effort with poor test design
  • Flaky tests can undermine trust in the suite
  • E2E tests are time-consuming and expensive to run

  • Test coverage

    Percentage of code or execution paths covered by tests.

  • Average test run time

    Average duration for running full test suite in CI.

  • Flakiness rate

    Share of tests that fail intermittently without code changes.

Unit testing with JUnit 5

A microservice uses JUnit 5 for isolated unit tests and Mockito for mocking dependencies.

Integration tests with Testcontainers

Integration tests start a temporary database via Testcontainers to reliably validate repository logic.

E2E checks in staging

Automated end-to-end suite verifies critical user journeys in staging before release.

1

Define basic test architecture, map the test pyramid and plan CI integration.

2

Write unit tests, use mocks and ensure local execution.

3

Introduce integration tests with Testcontainers and integrate into CI.

⚠️ Technical debt & bottlenecks

  • Outdated test APIs and lack of standardization
  • Unrefactored, slow test suites
  • Missing test isolation due to global states
Slow test runsFlaky testsComplex test infrastructure
  • Tests assert internal implementation details instead of public behavior
  • Using E2E tests for every commit instead of targeted checks
  • Lack of maintenance of old tests leads to false alarms
  • Underestimating effort for stable test data
  • Neglecting test infrastructure costs
  • Integrating tests into CI too late
Experience with Java and unit testingKnowledge of test automation and CIAbility to create stable test data
Fast feedback for developersReliable regression detectionAutomation in CI/CD pipelines
  • Limited test environments in CI
  • Budget for test infrastructure
  • Dependencies on third-party systems