Package com.google.common.truth
@CheckReturnValue
@NullMarked
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 subject for
BigDecimal
values.A subject forBoolean
values.A subject forClass
values.ComparableSubject<T extends Comparable<?>>A subject forComparable
values.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
.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>A subject forDouble
values.A partially specified check about an approximate relationship to adouble
value using a tolerance.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.ExpectFailure.SimpleSubjectBuilderCallback<S extends Subject, A>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."An opaque, immutable object containing state from the previous calls in the fluent assertion chain.Defines what to do when a check fails.A subject forFloat
values.A partially specified check about an approximate relationship to afloat
value using a tolerance.A subject for GuavaOptional
values.A subject forInteger
values.A partially specified check about an approximate relationship to aint
actual value using a tolerance.A subject forIntStream
values.A subject forIterable
values.A partially specified check in which the actual elements (normally the elements of theIterable
under test) are compared to expected elements using aCorrespondence
.A subject forLongStream
values.A subject forlong
values.A partially specified check about an approximate relationship to along
value using a tolerance.A subject forMap
values.A partially specified check in which the actual values (i.e. the values of theMap
under test) are compared to expected values using aCorrespondence
.A subject forMultimap
values.A partially specified check in which the actual values (i.e. the values of theMultimap
under test) are compared to expected values using aCorrespondence
.A subject forMultiset
values.A subject forObject[]
and more genericallyT[]
.A subject forOptionalDouble
values.A subject forOptionalInt
values.A subject forOptionalLong
values.A subject forOptional
values.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.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
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)
.A subject forfloat[]
.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)
.A subject forint[]
.A subject forlong[]
.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
.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)
.A subject forStream
values.A subject forString
values.Offers case-insensitive checks for string values.An object that lets you perform checks on the value under test.Subject.Factory<SubjectT extends Subject, ActualT>A subject forTable
values.A subject forThrowable
values.The primary entry point for Truth, a library for fluent test assertions.Deprecated.Subject forAssertionError
objects thrown by Truth.Provides a way to use Truth to perform JUnit "assumptions."
Truth
class.