DEV.co
Open-Source Testing · google

truth

Truth is a Java assertion library that makes test code more readable and failure messages clearer. Maintained by the Guava team and used extensively in Google's own tests, it provides fluent syntax for assertions on JDK and third-party types.

Source: GitHub — github.com/google/truth
2.8k
GitHub stars
269
Forks
Java
Primary language
Apache-2.0
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorygoogle/truth
Ownergoogle
Primary languageJava
LicenseApache-2.0 — OSI-approved
Stars2.8k
Forks269
Open issues76
Latest releasev1.4.5 (2025-09-10)
Last updated2026-07-06
Sourcehttps://github.com/google/truth

What truth is

Truth is an Apache 2.0 licensed assertion framework for Java/Android with native support for JDK and Guava types, extensible subject types, and fluent assertion chains. It provides custom failure message formatting to improve test debuggability and is maintained as part of the Guava project.

Quickstart

Get the truth source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/google/truth.gitcd truth# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit and integration testing in Java projects

Truth's fluent syntax and readable failure messages significantly improve test maintainability and debugging speed. Ideal for teams working on assertion-heavy test suites in JVM environments.

Testing Google ecosystem libraries and services

Since Truth is maintained by the Guava team and used across Google's codebase, it integrates naturally with Guava types and Google libraries. Strong choice if your stack includes Guava, Protocol Buffers, or Google Cloud libraries.

Custom assertion domain-specific languages (DSLs)

Truth's extension API allows creation of custom subjects and assertions for domain-specific types. Enables teams to build type-safe, readable assertions tailored to their business logic.

Implementation considerations

  • Add com.google.truth:truth dependency to Maven/Gradle build; import Truth static methods (assertThat, assertWithMessage) and integrate into existing test classes.
  • Truth integrates with JUnit via standard Java test runners; no special configuration required for basic usage.
  • Extensibility requires implementing Subject and SubjectFactory for custom types; document custom assertion APIs clearly for team adoption.
  • Fluent syntax changes assertion call patterns; plan for incremental migration of existing JUnit assertion code if moving from basic assertEquals style.
  • Truth's failure messages are automatically rich; no need for custom error handling, but leverage custom subjects to provide context-aware messages for domain objects.

When to avoid it — and what to weigh

  • Not using Java/JVM languages — Truth is Java-specific. Non-JVM projects need alternative assertion libraries.
  • Requiring heavy assertion library ecosystem features — For advanced mocking, stubbing, or behavior-driven development (BDD) syntax, consider frameworks that bundle these capabilities (e.g., JUnit + Mockito or Spock).
  • Minimal test framework footprint required — Truth adds a runtime dependency. Projects with strict dependency minimization policies may prefer JUnit's built-in assertions or alternative minimal assertion libraries.
  • Android projects with strict method count constraints — While Truth supports Android, method count overhead may be a concern in heavily constrained builds. Verify impact in your target configuration.

License & commercial use

Apache License 2.0 (Apache-2.0): Permissive OSI license. Grants rights to use, modify, and distribute. Includes liability disclaimer and trademark protection clause. Requires license and copyright notice preservation.

Apache 2.0 is a permissive license that explicitly permits commercial use, including closed-source applications. No commercial restrictions or proprietary licensing model applies. Redistribution requires license notice inclusion.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Truth is a test-time library with no network, file I/O, or privileged operations. Security surface is limited to test code paths. No known CVEs or security advisories referenced in provided data. Assess for code injection risks only if custom subjects process untrusted test inputs (uncommon).

Alternatives to consider

AssertJ

Similar fluent assertion library with broader third-party type support and more active community plugins. Consider if needing less Google-centric ecosystem integration.

JUnit 5 Assertions (org.junit.jupiter.api.Assertions)

Hamcrest Matchers

Older, matcher-based assertion library. More verbose syntax but very stable; consider only if already embedded in legacy test suite.

Software development agency

Build on truth with DEV.co software developers

Truth improves test readability and failure diagnostics with fluent assertions. Review the extension API and integration path with your JVM stack. Contact us to assess fit with your testing strategy and custom assertion needs.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

truth FAQ

Can Truth be used with existing JUnit tests?
Yes. Truth works as a drop-in replacement for JUnit assertions. Import static methods (assertThat) and replace assertEquals/assertTrue calls incrementally. No breaking changes to test infrastructure.
What is the performance impact of Truth compared to plain JUnit assertions?
Not stated in provided data. Recommend profiling in your test suite; assertion overhead is typically negligible in I/O-bound tests but measurable in unit test-heavy builds. Requires review.
Is Truth suitable for Android testing?
Yes, explicitly supported. Truth is designed for Android and natively supports Android types. Method count overhead should be verified for heavily constrained APK builds.
How do I write custom assertions for my domain objects?
Truth provides an extension API (truth.dev/extension) for implementing custom Subject subclasses. Document custom assertions clearly and publish as separate module if widely reused across teams.

Custom software development services

DEV.co helps companies turn open-source tools like truth into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source testing stack.

Evaluate Truth for Your Java Test Suite

Truth improves test readability and failure diagnostics with fluent assertions. Review the extension API and integration path with your JVM stack. Contact us to assess fit with your testing strategy and custom assertion needs.