Truth - Fluent assertions for Java

Truth makes your test assertions and failure messages more readable. Similar to AssertJ, it natively supports many JDK and Guava types, and it is extensible to others.

Truth is owned and maintained by the Guava team. It is used from the majority of the tests in Google’s own codebase.

How to use Truth

1. Add the appropriate dependency to your build file:




buildscript {
dependencies {
  testCompile ""

To use the Java 8 extensions, also include

2. Add static imports for Truth’s entry points:

import static;
import static;

// for assertions on Java 8 types
import static;

3. Write a test assertion:

String string = "awesome";
assertWithMessage("Without me, it's just aweso").that(string).contains("me");

Iterable<Color> googleColors = googleLogo.getColors();
    .containsExactly(BLUE, RED, YELLOW, BLUE, GREEN, RED)

If you’re using an IDE with autocompletion, it will suggest a list of assertions you can make about the given type. If not, consult the API docs. For example, if you’re looking for assertions about a Map, look at the documentation for MapSubject.

More information