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.
-
Interface Summary Interface Description Correspondence.BinaryPredicate<A extends @Nullable Object,E extends @Nullable Object> A functional interface for a binary predicate, to be used to test whether a pair of objects of typesA
andE
satisfy some condition.Correspondence.DiffFormatter<A extends @Nullable Object,E extends @Nullable Object> A functional interface to be used format the diff between a pair of objects of typesA
andE
.CustomSubjectBuilder.Factory<CustomSubjectBuilderT extends CustomSubjectBuilder> ExpectFailure.SimpleSubjectBuilderCallback<S extends Subject,A> A functional interface forexpectFailureAbout()
to invoke and capture failures.ExpectFailure.StandardSubjectBuilderCallback A functional interface forexpectFailure()
to invoke and capture failures.FailureStrategy Defines what to do when a check fails.Ordered 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.Subject.Factory<SubjectT extends Subject,ActualT> -
Class Summary Class Description BigDecimalSubject A subject forBigDecimal
values.BooleanSubject A subject forBoolean
values.ClassSubject A subject forClass
values.ComparableSubject<T extends Comparable<?>> A subject forComparable
values.Correspondence<A extends @Nullable Object,E extends @Nullable Object> Determines whether an instance of typeA
corresponds in some way to an instance of typeE
for the purposes of a test assertion.CustomSubjectBuilder In a fluent assertion chain, exposes one or more "custom"that
methods, which accept a value under test and return aSubject
.DoubleSubject A subject forDouble
values.DoubleSubject.TolerantDoubleComparison A partially specified check about an approximate relationship to adouble
value using a tolerance.Expect ATestRule
that batches up all failures encountered during a test, and reports them all together at the end (similar toErrorCollector
).ExpectFailure 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.Fact A string key-value pair in a failure message, such as "expected: abc" or "but was: xyz."FailureMetadata An opaque, immutable object containing state from the previous calls in the fluent assertion chain.FloatSubject A subject forFloat
values.FloatSubject.TolerantFloatComparison A partially specified check about an approximate relationship to afloat
value using a tolerance.GuavaOptionalSubject A subject for GuavaOptional
values.IntegerSubject A subject forInteger
values.IntegerSubject.TolerantIntegerComparison A partially specified check about an approximate relationship to aint
actual value using a tolerance.IntStreamSubject A subject forIntStream
values.IterableSubject A subject forIterable
values.IterableSubject.UsingCorrespondence<A extends @Nullable Object,E extends @Nullable Object> A partially specified check in which the actual elements (normally the elements of theIterable
under test) are compared to expected elements using aCorrespondence
.LongStreamSubject A subject forLongStream
values.LongSubject A subject forLong
values.LongSubject.TolerantLongComparison A partially specified check about an approximate relationship to along
value using a tolerance.MapSubject A subject forMap
values.MapSubject.UsingCorrespondence<A extends @Nullable Object,E extends @Nullable Object> A partially specified check in which the actual values (i.e. the values of theMap
under test) are compared to expected values using aCorrespondence
.MultimapSubject A subject forMultimap
values.MultimapSubject.UsingCorrespondence<A extends @Nullable Object,E extends @Nullable Object> A partially specified check in which the actual values (i.e. the values of theMultimap
under test) are compared to expected values using aCorrespondence
.MultisetSubject A subject forMultiset
values.ObjectArraySubject<T extends @Nullable Object> A subject forObject[]
and more genericallyT[]
.OptionalDoubleSubject A subject forOptionalDouble
values.OptionalIntSubject A subject forOptionalInt
values.OptionalLongSubject A subject forOptionalLong
values.OptionalSubject A subject forOptional
values.PathSubject A subject forPath
values.PrimitiveBooleanArraySubject A subject forboolean[]
values.PrimitiveByteArraySubject A subject forbyte[]
values.PrimitiveCharArraySubject A subject forchar[]
values.PrimitiveDoubleArraySubject A subject fordouble[]
values.PrimitiveDoubleArraySubject.DoubleArrayAsIterable A partially specified check for doing assertions on the array similar to the assertions supported forIterable
values, 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)
.PrimitiveFloatArraySubject A subject forfloat[]
values.PrimitiveFloatArraySubject.FloatArrayAsIterable A partially specified check for doing assertions on the array similar to the assertions supported forIterable
values, 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)
.PrimitiveIntArraySubject A subject forint[]
values.PrimitiveLongArraySubject A subject forlong[]
values.PrimitiveShortArraySubject A subject forshort[]
values.SimpleSubjectBuilder<SubjectT extends Subject,ActualT> In a fluent assertion chain, exposes the most commonthat
method, which accepts a value under test and returns aSubject
.StandardSubjectBuilder 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)
.StreamSubject A subject forStream
values.StringSubject A subject forString
values.StringSubject.CaseInsensitiveStringComparison Offers case-insensitive checks for string values.Subject An object that lets you perform checks on the value under test.TableSubject A subject forTable
values.ThrowableSubject A subject forThrowable
values.Truth The primary entry point for Truth, a library for fluent test assertions.Truth8 Deprecated. Instead of this class's methods, use the identical methods declared in the mainTruth
class.TruthFailureSubject A subject forAssertionError
objects thrown by Truth.TruthJUnit Provides a way to use Truth to perform JUnit "assumptions."