This release completes the feature that I got wrong in 1.1.1 -- the ability to exclude our JUnit 4 dependency and still use standard Truth assertions.
- Made it possible for users to exclude our JUnit 4 dependency and still use standard Truth assertions -- really this time, even in cases in which excluding the dependency failed under 1.1.1. (JUnit 4 is still required for some advanced features, like
Expect,ExpectFailure, andTruthJUnit.assume().) (948f3ed) - When JUnit 4 is excluded from the classpath, the
AssertionErrorTruth generates as a substitute forComparisonFailurenow includes the expected and actual values that were missing in 1.1.1. (6b01407)
We recommend not trying to exclude our JUnit dependency even under this release. We will release 1.1.2 with better handling for the missing dependency shortly.
Made it possible for users to exclude our JUnit 4 dependency and still use standard Truth assertions. (JUnit 4 is still required for some advanced features, likeExpect,ExpectFailure, andTruthJUnit.assume().) (2d65326)- Update: This appears to let users exclude the dependency in some cases but not all. We are working on a fix.
- Update 2: Also, even if you succeed in excluding the dependency in your environment, you will see failure messages that are missing information. We have a fix for this ready.
If you wish to exclude our JUnit dependency, you may wish to consider this alternative approach. That approach may be worthwhile even after we fix the bugs described above.
I apologize for the trouble.
- Fixed (we think :)) R8 compilation failure:
Error: com.android.tools.r8.errors.b: Compilation can't be completed because `org.objectweb.asm.ClassVisitor` and 1 other classes are missing.(0bfa285) - Added
unpackingAnyUsing(TypeRegistry, ExtensionRegistry). If you call this method,ProtoTruthwill attempt to unpackAnymessages before comparing them. (b50d878) - Added
formattingDiffsUsingmethods toIterableSubjectandMapSubject. This allows you to get failure messages which show diffs between the actual and expected elements (like you get withcomparingElementsUsing) while still comparing them using object equality. (ae997be) - Changed Checker Framework annotations from
checker-qualtoqual. (e71b57b) With this change, we inadvertently introduced Java 8 bytecode into our dependencies. Please report problems on #882. Sorry for the trouble. - Added null checks to
StringSubject. (3481ab0) - Included ASM as a dependency (non-
<optional>) by default. It is still safe to exclude if you want to minimize dependencies, but by including it, you may see better failure messages. (aea78e8) - Removed dependency on
gwt-user. (b54e9ef) - API documentation for Truth classes is now easier to reach. For example, for
StringSubject, visit truth.dev/StringSubject. Also, more easily access the index at truth.dev/api.
- Changed failure messages to identify trailing whitespace in failed string comparisons. (7a58a45)
- Moved
gwt-usertotestscope. (51bbbf4) - Fixed handling of proto maps with keys equal to the key type's default value. (8ebfe2a)
- Worked around what seems to be a classloading bug in old versions of some vendors' Android runtimes. (02c5e79)
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 full documentation at truth.dev, or start with our higher-level blog post.
Users of AssertJ will be particularly interested in our comparison of Truth and AssertJ.
Truth 1.0 contains no changes relative to 1.0-rc2. For a list of changes since Truth 0.46, see the release notes for rc1 and rc2.
Now that we have reached 1.0 (after eight years! We're sorry, and we thank you again for your patience), we will maintain binary compatibility.
Sorry for the last-second changes. We still expect to release 1.0 on July 8.
- Changed
DoubleSubjectandFloatSubjectto overrideisEqualToandisNotEqualToinstead of declaring an overload. (4743c14) - Changed
MultimapSubject.UsingCorrespondencemethodscontainsExactlyandcontainsAtLeastto require anEfor their one non-varargs value argument, and removed their type parameters. (4743c14) - Eliminated type parameters on
MapSubject.UsingCorrespondenceandMultimapSubject.UsingCorrespondencemethodscontainsExactlyEntriesInandcontainsAtLeastEntriesIn. (4743c14) - Changed
IntStreamSubjectandLongStreamSubjectmethodsisInOrderandisInStrictOrderto require a compatibleComparator. (4743c14)
We expect to release 1.0 (and publish an official announcement) on Monday, July 8.
- Made
assertThat(0.0).isEqualTo(0)pass, despite the mix ofdoubleandint. (And likewise forfloatandint.) This extends existing support that previously applied only to integral types. (1c5f9e8) - Added
intoverloads ofisGreaterThan,isLessThan,isAtLeast, andisAtMost. (dc92786) - Removed the overload of
StandardSubjectBuilder.fail(...)that accepts a message. Instead ofassert_().fail(...), useassertWithMessage(...).fail(). Similarly, instead ofexpect.fail(...), useexpect.withMessage(...).fail(), and so forth. (f6875d6) - Removed
DefaultSubject. Use plainSubject. (f6875d6) - Removed
AtomicLongMapSubject. In most cases, you can assert on theasMap()view instead. (f6875d6) - Removed
Optional*Subject.hasValueThat(). Instead ofassertThat(optional).hasValueThat()...., useassertThat(optional.getAs*())..... (f6875d6)
- Removed deprecated
containsAllOfandcontainsAllIn. UsecontainsAtLeastandcontainsAtLeastElementsIn, which are equivalent. (5de3d21) - Removed deprecated
isOrderedandisStrictlyOrdered. UseisInOrderandisInStrictOrder, which are equivalent. (5de3d21) - Removed deprecated
SortedMapSubjectandSortedSetSubject. Users will have to perform assertions directly on the result of methods likefirstKey. We haven't found sufficient demand for the classes to keep them. (057ef31) - Removed deprecated
ListMultimapSubject,SetMultimapSubject, and ProtoTruth equivalents, which add little to the generalMultimapsubjects. (057ef31) - Removed the type parameters from
Subject. If you subclass this type (or declare it as a method return type, etc.), you will have to update those usages at the same time you update Truth. Or you can remove the type parameters from your usages (temporarily introducing rawtypes/unchecked warnings, which you may wish to suppress) and then update Truth (at which point the warnings will go away and you can remove any suppressions). (3740ee6) To remove the type parameters fromSubjectsubclasses, you can get most of the way there with a Perl-compatible regex search-and-replace operation:s/\bSubject<([^<>]*|[^<>]*<[^<>]*>[^<>]*|[^<>]*<[^<>]*>[^<>]*<[^<>]*>[^<>]*|[^<>]*<[^<>]*<[^<>]*>[^<>]*>)>/Subject/g - Removed the self-type parameter of
ComparableSubjectand most of the type parameters ofIterableOfProtosSubject,MapWithProtoValuesSubject, andMultimapWithProtoValuesSubject. If you subclass any of those types (or declare them as method return types, etc.), you will have to update those usages at the same time you update Truth. Or you can remove the type parameters from your usages, update Truth, and then add back the remaining type parameters. (e611568) - Removed the type parameters of
ProtoSubjectandLiteProtoSubject. If you subclass either of those types (or declare them as method return types, etc.), you will have to update those usages at the same time you update Truth. Or you can remove the type parameters from your usages (temporarily introducing rawtypes/unchecked warnings, which you may wish to suppress) and then update Truth (at which point the warnings will go away and you can remove any suppressions). (eb3852c) - Removed deprecated
actual(),getSubject(),named(),internalCustomName(), andactualAsString(). To automate most migrations, we've providedStoreActualValueInFieldandNamedToWithMessage(and a quick-and-dirty regex version for common cases). (If you are migrating manually, you may need to know how to handlejava.util.Optional,Stream, and other types that aren't built in.) You might also be interested in our notes from the API Review of this decision. (c1db1b7) - Changed
ProtoSubjectto not extendProtoFluentAssertion. It still contains all the same methods, except thatisEqualToandisNotEqualTonow require aMessage, rather than accept anyObject. (777af33) - Deprecated the overload of
StandardSubjectBuilder.fail(...)that accepts a message. Instead ofassert_().fail(...), useassertWithMessage(...).fail(). Similarly, instead ofexpect.fail(...), useexpect.withMessage(...).fail(), and so forth. (227b559) - Deprecated
AtomicLongMapSubject. In most cases, you can assert on theasMap()view instead. (19e1f22) - Deprecated
Optional*Subject.hasValueThat(). Instead ofassertThat(optional).hasValueThat()...., useassertThat(optional.getAs*())..... (227b559) - Changed
assertWithMessageto throw an exception if given format arguments but a null format string. (31e44cc) - Reimplemented the message-accepting overload of
fail(...)in terms ofwithMessage(...). This is mostly a no-op but can affect behavior in unusual cases. For details, see the commit description. (a52f89b) - Made
IterableSubject.isEqualToproduce the same message format ascontainsExactly. (27a9111) - Introduced
TruthFailureSubject.truthFailures()factory for callers that want to test Truth failure messages withexpect,assertWithMessage, etc. (c1db1b7)
We are pushing hard to release a Truth 1.0 by June 30, after which we don't expect to remove any more APIs. Thanks for your patience with both our slow progress over the past several years and our rapid churn now.
To use the migration tools below, you'll need to set up Error Prone and configure our tools as plugins to run in patch mode.
Deletions:
- Removed deprecated
Subject.isSameAsandisNotSameAs. UseisSameInstanceAsandisNotSameInstanceAs, which are equivalent. (36200e6) - Hid the constuctor of
Correspondence. Use the class's static factory methods instead. The most mechanical migration is usually toCorrespondence.from. To help with migration, we're releasedCorrespondenceSubclassToFactoryCall. (11da1ca) - Removed deprecated
Subject.fail*methods. SeeSubject.failWithActualandfailWithoutActual, which use the newFactclass. To help with migration, we're releasedFailWithFacts(and alsoImplementAssertionWithChaining, which is also sometimes useful for these migrations), though you will likely need to make manual changes, as well. (36200e6) - Removed deprecated no-arg
Subject.check(). Use the overload that accepts a description. (To help with this migration, we have addedProvideDescriptionToCheckto Error Prone -- but then removed it before it became part of a release, so you'll need to pull it in manually.) (36200e6) - Removed deprecated
MathUtil. For similar static methods, see Guava'sDoubleMath.fuzzyEquals. But callers from customSubjectimplementations may prefer an approach likecheck("score()").that(actual.score()).isWithin(tolerance).of(expected). (7b2876d) - Removed deprecated
createAndEnableStackTrace(). Usecreate(), which now also enables stack traces. (9362f4c)
Deprecations:
- Deprecated
isOrdered()andisStrictlyOrdered(). UseisInOrder()andisInStrictOrder(), which are equivalent. (146080a, 386207d) - Deprecated
containsAll*on ProtoTruth,*StreamSubject, andPrimitive*ArraySubject.*ArrayAsIterable. UsecontainsAtLeast*, which is equivalent. (82c1f2d, 386207d) - Deprecated
Subject.actual(). Instead of calling it, declare your own field to store the actual value. To automate most migrations, we've providedStoreActualValueInField. (297c0f1) - Deprecated
Subject.named. Instead ofassertThat(foo).named("foo"), useassertWithMessage("foo").that(foo). For custom subjects, useassertWithMessage("foo").about(foos()).that(foo). For other scenarios, see this FAQ entry about adding messages. To automate most migrations, we've providedNamedToWithMessage(and a quick-and-dirty regex version for common cases). You might be interested in our notes from the API Review of this decision. (08afb24) - "Deprecated" the type parameters on
Subject. To prepare for their removal in the next release, you can edit your code today to refer to the rawSubjecttype. (KotlinSubjectauthors, see below.) Also "deprecated" the self-type parameter onComparableSubject. Again, you can prepare your code by referring to rawComparableSubject(and later change it to refer toComparableSubject<T>when the class has only one type parameter next release). Similarly, "deprecated" the type parameters onProtoSubjectandLiteProtoSubject, along with most of the type parameters ofIterableOfProtosSubject,MapWithProtoValuesSubject, andMultimapWithProtoValuesSubject. (21c29f7, 5abd9ed) - Loosened type parameters on
Subject.Factory. This permits customSubjectsubclasses extend rawSubjectinstead ofSubject<FooSubject, Foo>to prepare for when we remove the type parameters fromSubjectentirely. - Deprecated
DefaultSubject. Use plainSubject. (7b5311b) - Deprecated
SortedMapSubjectandSortedSetSubject. Users will have to perform assertions directly on the result of methods likefirstKey. We haven't found sufficient demand for the classes to keep them. (46aebcf) - Deprecated the
SetMultimap-specific andListMultimap-specificSubjects, which add little to the generalMultimapsubjects. (2103fee) - Deprecated
actualAsString()andinternalCustomName(). They exist primarily to supportnamed(), which is being removed. (d69ba29)
Other migration notes:
- The order in which you migrate can be important: Migrate off
actual()andnamed()before removing type parameters from customSubjectclasses. - The tool we'll release for migrating off
namedrequires that customSubjectclasses expose aSubject.Factory, as described in our docs about extensions. - To remove the type parameters from
Subjectsubclasses, you can get most of the way there with a Perl-compatible regex search-and-replace operation:s/\bSubject<([^<>]*|[^<>]*<[^<>]*>[^<>]*|[^<>]*<[^<>]*>[^<>]*<[^<>]*>[^<>]*|[^<>]*<[^<>]*<[^<>]*>[^<>]*>)>/Subject/g
Features:
- For very simple tests, failure messages will include a "value of:" line. For example, the failure message of
assertThat(fetchLogMessages()).isEmpty()might contain "value of: fetchLogMessages()." This feature is not available under Android or GWT, and it is only available if you have ASM on your classpath. - Exposed the constructors of
ThrowableSubject,MapSubject, andMultimapSubjectto subclasses. Note that actually extending those subjects won't fully work until we remove the type parameters fromSubject. (1a39d5a, 32f76a5) - Temporarily made
DefaultSubjectextensible again. Kotlin subjects can now extendDefaultSubjectinstead ofSubject. This lets those subjects compile both before and after we remove the type parameters fromSubject. After we remove the type parameters, Kotlin subjects should extendSubjectagain (with no type parameters), as we'll later removeDefaultSubject. (6e45b27) - Made ProtoTruth
Subjectclasses extendIterableSubject,MapSubject, andMultimapSubject. (1a39d5a). - Updated stack-trace cleaning to handle reflection under Java 9.