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,E> 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,E> A functional interface to be used format the diff between a pair of objects of typesA
andE
.CustomSubjectBuilder.Factory<CustomSubjectBuilderT extends CustomSubjectBuilder> ErrorWithFacts Supertype of Truth'sAssertionError
subclasses that are created from a list ofFact
instances.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.IterableSubject.PairwiseChecker MapSubject.ValueTester<A,E> 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.Platform.JUnitTestRule Wrapping interface ofTestRule
to be used within truth.Subject.Factory<SubjectT extends Subject,ActualT> -
Class Summary Class Description AbstractArraySubject A common supertype for Array subjects, abstracting some common display and error infrastructure.ActualValueInference Given the stack frame of a failing assertion, tries to describe what the user passed toassertThat
.ActualValueInference.DescribedEntry An entry that contains a description of how it was created.ActualValueInference.FrameInfo A value class to represent a frame.ActualValueInference.InferenceClassVisitor ActualValueInference.InferenceMethodVisitor ActualValueInference.InferredType This is the type used for type inference.ActualValueInference.Invocation A method invocation.ActualValueInference.Invocation.Builder ActualValueInference.OpaqueEntry An entry that we know nothing about except for its type.ActualValueInference.StackEntry 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.ActualValueInference.SubjectEntry AutoValue_ActualValueInference_DescribedEntry AutoValue_ActualValueInference_FrameInfo AutoValue_ActualValueInference_InferredType AutoValue_ActualValueInference_Invocation AutoValue_ActualValueInference_Invocation.Builder AutoValue_ActualValueInference_OpaqueEntry AutoValue_ActualValueInference_SubjectEntry BigDecimalSubject Propositions forBigDecimal
typed subjects.BooleanSubject Propositions for boolean subjects.ClassSubject Propositions forClass
subjects.ComparableSubject<T extends java.lang.Comparable> Propositions forComparable
typed subjects.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.Correspondence.ExceptionStore Helper object to store exceptions encountered while executing aCorrespondence
method.Correspondence.FormattingDiffs<A,E> Correspondence.FromBinaryPredicate<A,E> Correspondence.StoredException Correspondence.TolerantNumericEquality Correspondence.Transforming<A,E> CustomSubjectBuilder In a fluent assertion chain, exposes one or more "custom"that
methods, which accept a value under test and return aSubject
.DoubleSubject Propositions forDouble
subjects.DoubleSubject.TolerantDoubleComparison A partially specified check about an approximate relationship to adouble
subject using a tolerance.Expect ATestRule
that batches up all failures encountered during a test, and reports them all together at the end (similar toErrorCollector
).Expect.ExpectationGatherer 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."Facts Helper class that wraps a collection ofFact
instances to make them easier to build.FailureMetadata An opaque, immutable object containing state from the previous calls in the fluent assertion chain.FailureMetadata.Step The data from a call to either (a) aSubject
constructor or (b)Subject.check()
.FloatSubject Propositions forFloat
subjects.FloatSubject.TolerantFloatComparison A partially specified check about an approximate relationship to afloat
subject using a tolerance.GraphMatching Helper routines related to graph matchings.GraphMatching.HopcroftKarp<U,V> Helper which implements the Hopcroft–Karp algorithm.GuavaOptionalSubject Propositions for GuavaOptional
subjects.IntegerSubject Propositions forInteger
subjects.IntStreamSubject Propositions forIntStream
subjects.IterableSubject Propositions forIterable
subjects.IterableSubject.UsingCorrespondence<A,E> A partially specified check in which the actual elements (normally the elements of theIterable
under test) are compared to expected elements using aCorrespondence
.LazyMessage LongStreamSubject Propositions forLongStream
subjects.LongSubject Propositions forlong
subjects.MapSubject Propositions forMap
subjects.MapSubject.MapDifference<K,A,E> MapSubject.TypedToStringWrapper MapSubject.ValueDifference<A,E> MathUtil Math utilities to be shared by numeric subjects.MultimapSubject Propositions forMultimap
subjects.MultimapSubject.EntryCorrespondence<K,A,E> MultimapSubject.IterableEntries MultisetSubject Propositions forMultiset
subjects.ObjectArraySubject<T> A Subject forObject[]
and more genericallyT[]
.OptionalDoubleSubject Propositions for Java 8OptionalDouble
subjects.OptionalIntSubject Propositions for Java 8OptionalInt
subjects.OptionalLongSubject Propositions for Java 8OptionalLong
subjects.OptionalSubject Propositions for Java 8Optional
subjects.PathSubject Assertions forPath
instances.Platform Extracted routines that need to be swapped in for GWT, to allow for minimal deltas between the GWT and non-GWT version.PrimitiveBooleanArraySubject A Subject forboolean[]
.PrimitiveByteArraySubject A Subject forbyte[]
.PrimitiveCharArraySubject A Subject forchar[]
.PrimitiveDoubleArraySubject A Subject fordouble[]
.PrimitiveDoubleArraySubject.DoubleArrayAsIterable 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)
.PrimitiveFloatArraySubject A Subject forfloat[]
.PrimitiveFloatArraySubject.FloatArrayAsIterable 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)
.PrimitiveIntArraySubject A Subject forint[]
.PrimitiveLongArraySubject A Subject forlong[]
.PrimitiveShortArraySubject A Subject forshort[]
.SimpleSubjectBuilder<SubjectT extends Subject,ActualT> In a fluent assertion chain, exposes the most commonthat
method, which accepts a value under test and returns aSubject
.StackTraceCleaner Utility that cleans stack traces to remove noise from common frameworks.StackTraceCleaner.StackTraceElementWrapper Wrapper around aStackTraceElement
for calculating and holding the metadata used to clean the stack trace.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 Propositions forStream
subjects.StringSubject Propositions for string subjects.Subject An object that lets you perform checks on the value under test.Subject.ComparisonResult The result of comparing two objects for equality.SubjectUtils Utility methods used inSubject
implementors.SubjectUtils.DuplicateGroupedAndTyped Missing or unexpected values from a collection assertion, with equal objects grouped together and, in some cases, type information added.SubjectUtils.NonHashingMultiset<E> TableSubject Propositions forTable
subjects.ThrowableSubject Propositions forThrowable
subjects.Truth The primary entry point for Truth, a library for fluent test assertions.Truth8 The primary entry point for assertions about Java 8 types.TruthFailureSubject Subject forAssertionError
objects thrown by Truth.TruthJUnit Provides a way to use Truth to perform JUnit "assumptions." An assumption is a check that, if false, aborts (skips) the test. -
Enum Summary Enum Description Expect.TestPhase FailureMetadata.OldAndNewValuesAreSimilar 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.IterableSubject.ElementFactGrouping Whether to output each missing/unexpected item as its ownFact
or to group all those items together into a singleFact
.StackTraceCleaner.StackFrameType Enum of the package or class-name based categories of stack frames that might be removed or collapsed by the cleaner.Subject.EqualityCheck -
Exception Summary Exception Description Platform Extracted routines that need to be swapped in for GWT, to allow for minimal deltas between the GWT and non-GWT version.TruthJUnit.ThrowableAssumptionViolatedException -
Error Summary Error Description AssertionErrorWithFacts AnAssertionError
composed of structuredFact
instances and other string messages.ComparisonFailureWithFacts AnAssertionError
(usually a JUnitComparisonFailure
, but not under GWT) composed of structuredFact
instances and other string messages.Platform.PlatformComparisonFailure Truth.SimpleAssertionError 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. -
Annotation Types Summary Annotation Type Description ActualValueInference.Nullable