Package com.google.common.truth
package com.google.common.truth
Truth is a library for performing assertions in
tests:
assertThat(notificationText).contains("testuser@google.com");
Truth is owned and maintained by the Guava team. It is used in the majority of the tests in Google’s own codebase.
For more information, see our introduction and other docs.
-
ClassDescriptionA common supertype for Array subjects, abstracting some common display and error infrastructure.Given the stack frame of a failing assertion, tries to describe what the user passed to
assertThat
.An entry that contains a description of how it was created.A value class to represent a frame.This is the type used for type inference.A method invocation.An entry that we know nothing about except for its type.An entry on the stack (or the local-variable table) with a type and sometimes a description of how the value was produced or, as a special case, whether the value is a Truth subject.AnAssertionError
composed of structuredFact
instances and other string messages.Propositions forBigDecimal
typed subjects.Propositions for boolean subjects.Propositions forClass
subjects.ComparableSubject<T extends Comparable>Propositions forComparable
typed subjects.AnAssertionError
(usually a JUnitComparisonFailure
, but not under GWT) composed of structuredFact
instances and other string messages.Correspondence<A,E> Determines whether an instance of typeA
corresponds in some way to an instance of typeE
for the purposes of a test assertion.A functional interface for a binary predicate, to be used to test whether a pair of objects of typesA
andE
satisfy some condition.A functional interface to be used format the diff between a pair of objects of typesA
andE
.Helper object to store exceptions encountered while executing aCorrespondence
method.In a fluent assertion chain, exposes one or more "custom"that
methods, which accept a value under test and return aSubject
.CustomSubjectBuilder.Factory<CustomSubjectBuilderT extends CustomSubjectBuilder>Propositions forDouble
subjects.A partially specified check about an approximate relationship to adouble
subject using a tolerance.Supertype of Truth'sAssertionError
subclasses that are created from a list ofFact
instances.ATestRule
that batches up all failures encountered during a test, and reports them all together at the end (similar toErrorCollector
).A utility for testing that assertions against a customSubject
fail when they should, plus a utility to assert about parts of the resulting failure messages.A "functional interface" forexpectFailureAbout()
to invoke and capture failures.A "functional interface" forexpectFailure()
to invoke and capture failures.A string key-value pair in a failure message, such as "expected: abc" or "but was: xyz."Helper class that wraps a collection ofFact
instances to make them easier to build.An opaque, immutable object containing state from the previous calls in the fluent assertion chain.Whether the value of the original subject and the value of the derived subject are "similar enough" that we don't need to display both.The data from a call to either (a) aSubject
constructor or (b)Subject.check()
.Defines what to do when a check fails.Propositions forFloat
subjects.A partially specified check about an approximate relationship to afloat
subject using a tolerance.Helper routines related to graph matchings.Helper which implements the Hopcroft–Karp algorithm.Propositions for GuavaOptional
subjects.Propositions forInteger
subjects.Propositions forIntStream
subjects.Propositions forIterable
subjects.Whether to output each missing/unexpected item as its ownFact
or to group all those items together into a singleFact
.A partially specified check in which the actual elements (normally the elements of theIterable
under test) are compared to expected elements using aCorrespondence
.Propositions forLongStream
subjects.Propositions forlong
subjects.Propositions forMap
subjects.MapSubject.MapDifference<K,A, E> Math utilities to be shared by numeric subjects.Propositions forMultimap
subjects.Propositions forMultiset
subjects.A Subject forObject[]
and more genericallyT[]
.Propositions for Java 8OptionalDouble
subjects.Propositions for Java 8OptionalInt
subjects.Propositions for Java 8OptionalLong
subjects.Propositions for Java 8Optional
subjects.Returned by calls likeIterableSubject.containsExactly(java.lang.Object...)
,Ordered
lets the caller additionally check that the expected elements were present in the order they were passed to the previous calls.Assertions forPath
instances.Extracted routines that need to be swapped in for GWT, to allow for minimal deltas between the GWT and non-GWT version.A GWT-swapped version of test rule interface that does nothing.A Subject forboolean[]
.A Subject forbyte[]
.A Subject forchar[]
.A Subject fordouble[]
.A partially specified check for doing assertions on the array similar to the assertions supported forIterable
subjects, in which the elements of the array under test are compared to expected elements using either exact or tolerant double equality: seePrimitiveDoubleArraySubject.usingExactEquality()
andPrimitiveDoubleArraySubject.usingTolerance(double)
.A Subject forfloat[]
.A partially specified check for doing assertions on the array similar to the assertions supported forIterable
subjects, in which the elements of the array under test are compared to expected elements using either exact or tolerant float equality: seePrimitiveFloatArraySubject.usingExactEquality()
andPrimitiveFloatArraySubject.usingTolerance(double)
.A Subject forint[]
.A Subject forlong[]
.A Subject forshort[]
.In a fluent assertion chain, exposes the most commonthat
method, which accepts a value under test and returns aSubject
.Utility that cleans stack traces to remove noise from common frameworks.Enum of the package or class-name based categories of stack frames that might be removed or collapsed by the cleaner.Wrapper around aStackTraceElement
for calculating and holding the metadata used to clean the stack trace.In a fluent assertion chain, an object with which you can do any of the following: Set an optional message withStandardSubjectBuilder.withMessage(java.lang.String)
.Propositions forStream
subjects.Propositions for string subjects.An object that lets you perform checks on the value under test.The result of comparing two objects for equality.Utility methods used inSubject
implementors.Missing or unexpected values from a collection assertion, with equal objects grouped together and, in some cases, type information added.Propositions forTable
subjects.Propositions forThrowable
subjects.The primary entry point for Truth, a library for fluent test assertions.AnAssertionError
that (a) always supports a cause, even under old versions of Android and (b) omits "java.lang.AssertionError:" from the beginning of its toString() representation.The primary entry point for assertions about Java 8 types.Subject forAssertionError
objects thrown by Truth.Provides a way to use Truth to perform JUnit "assumptions." An assumption is a check that, if false, aborts (skips) the test.