Releases: google/truth
Releases · google/truth
Truth 0.41
- Changed most of Truth's failure messages to a multi-line, key-value format. Provided an API for testing messages of this format. (4a51035)
- Introduced the new API for building failure messages in a "key: value" format. See
Subject.failWithActual
andfailWithoutActual
, which use the newFact
class. (e06ca85) - Changed the old API's failure messages to automatically add a "name: ..." field if the user called
named()
. In some cases, this adds a name where it was missing before; in others, it duplicates a name that is already present. The long-term fix for this will be to migrate to the new failure API, which always includes the name once, and possibly also to deletenamed()
in favor ofwithMessage()
. (911c939) - Deprecated
failWithRawMessageAndCause
. Truth automatically attaches the cause if it's part of the assertion chain. If not, see the deprecation docs for the workaround. (3622e9c) - Deprecated
failComparing
. Usecheck("foo").that(actual().foo()).isEqualTo(expectedFoo)
. (2db2a4f) - Deprecated the remaining legacy
fail*
methods. (1f9b2d6) - Hid
protected
methodIterableSubject.failWithBadResultsAndSuffix()
(5becbfe). - Started throwing
ComparisonFailure
fromMapSubject.containsEntry
. (4330ec6) - Started throwing
ComparisonFailure
fromassertThat(singleElementIterable).containsExactly(otherSingleElementIterable)
. (e44edd1) - Added code to remove
Runner
andStatement
frames from the stack trace. (d2bb074) - Added
StringSubject.ignoringCase()
(13e8054) - Added
ignoringExtraRepeatedFieldElements()
to ProtoTruth. (f070204) - Added
comparingExpectedFieldsOnly()
to ProtoTruth. (08908c1) - Removed deprecated
MultimapSubject.containsExactly(Multimap)
. UsecontainsExactlyEntriesIn(Multimap)
. (containsExactly(Object k0, Object v0, Object... rest)
continues to exist.) (9c80ad5) - Removed deprecated
isPartiallyOrdered()
methods. UseisOrdered()
(5becbfe). - Started throwing UOE from
IterableSubject.isNoneOf()
andisNotIn()
. (46c8d3d) - Switched to Checker Framework
@NullableDecl
instead of jsr305@Nullable
. Tools that read these annotations may need to be updated to recognize the new annotation. (10ee459)
Truth 0.40
- Added
check(String template, Object... args)
. Most users ofcheck()
should migrate. If the new method doesn't suit your needs, please file a bug. (187a969) - Removed
getDisplaySubject()
, and markedactualCustomStringRepresentation()
as@ForOverride
. Callers should useactualAsString()
; overriders should useactualCustomStringRepresentation()
. (47ea976, 24d4c96) - Made
assertThat(array).isEqualTo(otherArray)
compare arrays contents (not array identity) even when the input wasn't statically known to be an array. (ece35ac) - Began cleaning stack traces from custom subjects outside of core Truth. (7a6f69d)
- Enhanced
Expect
to omit stack frames common to multiple failures. (48b31f7) - Put any user messages on their own lines, separate from the main failure message. (6d060b8)
- Tweaked the format of array failure messages. (ece35ac)
- Removed the type name from the output of arrays. (f4fabf2)
- For array subjects, made
named()
supplement the existing actual value text, not replace it. This brings it in line with other subjects' behaviors. (f4fabf2) - Tweaked failure messages for array
asList()
assertions. (df5c101) - Tweaked failure messages for
isAnyOf
,isNone
, andisNotIn
to be more consistent. (6233d1b) - Changed
Subject.fail(String, Object)
to stop including class names if the Object's toString() representation matches the value under test's. (This is likely to be uncommon unless you are overridingisEqualTo()
, in which case we recommend delegating tosuper.isEqualTo()
when possible.) (7af9c56) - Stopped calling
actual.equals(null)
; all objects are assumed to be not equal tonull
. (c1ab4ed) - Added
displayingDiffsPairedBy
toIterableOfProtosSubject
. (a51fc7a) - Add support for float and double comparisons in ProtoTruth. (6cd8068)
- Check only the descriptor identity before comparing messages in ProtoSubject. (7df5790)
- Add formatted diffs for ProtoTruth Correspondence comparisons. (4b790a3)
- Removed deprecated
(Object expected, double tolerance)
overloads ofisEqualTo()
andisNotEqualTo()
. (ca04f65) - Added the
@CompatibleWith
annotation from http://errorprone.info toisSameAs
,isNotSameAs
,isAnyOf
, andisNoneOf
. (2487651) - Made
assertThat(...).is{,Not}InstanceOf(SomeInterface.class)
blow up with a helpful message under GWT, rather than always fail in the case ofisInstanceOf
and always succeed in the case ofisNotInstanceOf
. (026d922) - Made
assertThat(null).isInstanceOf(...)
fail()
under GWT instead of throwNullPointerException
. (026d922)
Truth 0.39
- Changed
FailureStrategy
to a one-method interface:fail(AssertionError)
, removingAbstractFailureStrategy
.
Truth 0.38
- Added overloads to
containsExactlyElementsIn()
and similar methods to accept arrays. - Made
Expect
support concurrent calls tofail()
. - Truth is now built with
-target 7
. However, it continues to depend on only "Java-6-like" APIs so that it continues to work on old versions of Android. (1688736) - Worked around GWT's buggy handling of
double[]
equality. Also, changed the rendering ofdouble[]
values under GWT to more closely match Java. The change requires an API that isn't present in older browers, so please report any problems you encounter. (1a4c679) - Made
StandardSubjectBuilder.check()
final. (1d44b58)
Truth 0.37
- Delete
Subject.failureStrategy
. UseSubject.fail*
. - Delete
Truth.THROW_ASSERTION_ERROR
andTruthJUnit.throwAssumptionError()
. UseTruth.assert_()
andTruthJUnit.assume()
(and methods likefail()
andabout(...).that(...)
on the resulting objects). - Delete
SubjectFactory
andCustomSubjectBuilderFactory
. Use nested typesSubject.Factory
andCustomSubjectBuilder.Factory
, which accept new typeFailureMetadata
rather thanFailureStrategy
. - Make some Subject constructors
protected
now that they're useful only from subclasses. - Prevent subclassing of
DefaultSubject
entirely: UseSubject
. - Enhanced our stripping of stack traces.
Truth 0.36
- Delete the
*Verb*
types and associated classes (after migrating Proto-Truth). - Delete
ExpectationGatherer
. - Deprecate
Subject.failureStrategy
, introducing moreSubject.fail*
methods to take its place. - Deprecate
Truth.THROW_ASSERTION_ERROR
andTruthJUnit.throwAssumptionError()
. Users should useTruth.assert_()
andTruthJUnit.assume()
(and methods likefail()
andabout(...).that(...)
on the resulting objects). - Deprecate
SubjectFactory
andCustomSubjectBuilderFactory
, introducing nested typesSubject.Factory
andCustomSubjectBuilder.Factory
to take their place. The nested types accept new typeFailureMetadata
rather thanFailureStrategy
, and ourSubject
classes have been updated accordingly. The main benefit is that, once you update yourSubject
constructors to acceptFailureMetadata
, you can expose aSubject.Factory
, and it can usually be implemented with a method reference:return FooSubject::new
;.
Truth 0.35
- Remove
withFailureMessage
, the old name ofwithMessage
. - Remove
assertAbout(...).withFailureMessage(...)
in favor ofassertWithMessage(...).about(...)
. - Deprecate
ExpectationGatherer
. - Deprecate the
*Verb*
types in favor of new*SubjectBuilder*
types. - Add subjects for
IntStream
andLongStream
. - Add the no-arg
MultimapSubject.containsExactly()
method. - Call out empty strings more clearly in collection subjects' failure messages.
- Make various subjects behave better when used with
Expect
. Primarily, make any given assertion call fail at most once. - In
Expect
, always output failed expectations, even if an exception is thrown, and always fail the test, even if the exception was expected. Also, always include a stack trace when one was requested, even if the assertion specifies an additional cause. - Upgrade Guava dependency. You might notice that we now depend on 22.0-android. Guava says to depend on the Android version because Truth is usable on both Android and the JRE. If Maven or another build tool starts to give you 22.0-android at runtime instead of the "normal" version of Guava, you can override it.
Truth 0.34
- Add
MultimapSubject.containsExactly
. - Remove the redundant synthetic cause from truth assertion errors.
- Begin renaming
withFailureMessage
towithMessage
(onAbstractVerb
/TestVerb
). - Deprecate
assertAbout(...).withFailureMessage(...)
in favor ofassertWithMessage(...).about(...)
. FailureStrategy
is fully abstract. Users should preferAbstractFailureStrategy
or one of the alternatives detailed in the javadocs.- Lock down assorted APIs that aren't meant to be used / used publicly / subtyped.
Truth 0.33
Changes to existing Subjects and Core classes
- [API] Introduce
ExpectFailure
, a common mechanism for capturing failures in Truth, allowing tests to verify Truth failures without catchingAssertionError
. Intended primarily for testingSubject
implementations. - [API] Deprecate
PrimitiveDoublesArraySubject.hasvaluesWithin()
and
PrimitiveFloatArraySubject.hasvaluesWithin()
. - [SPI] Introduce
AbstractFailureStrategy
; users creating their own customFailureStrategy
implementations are encouraged to migrate to this class if possible. - [SPI] Add
Subject.ignoreCheck()
which is similar toSubject.check()
but passes a no-op failure strategy, to
allow chaining to continue when non-short-circuiting failure strategies are used (such asExpect
). - Restrict visibility of the
Platform
class, which was never intended to be part of the public API. Most usages can simply be removed / inlined, usages that require GWT compatibility should open feature requests.
Extensions
-
Protocol Buffers
- Permit Iterables for field numbers, descriptors, and handles with the protocol buffers FieldScope APIs
- Fix comparison rules for map fields.
Fixes
- Typo in
LiteProtoTruth
docs assertThat(Double.NaN).isNaN()
in gwt/j2cl now working properly.- Variety of improvements to error messages in MultimapSubject and MapSubject
ThrowableSubject
and Java8Optional*Subject
tests now useExpectFailure
which exposed some bad behavior, now fixed.IterableSubject
adds type information to errors when string representations are the same, to clarify some
ambiguous cases
Misc
- Internal clean-up of
FailureStrategy
usage to prepare forFailureStrategy
becoming fully abstract - Source now formatted via google-java-format
- For users of ErrorProne, add
@SuppressWarnings("TruthSelfEquals")
since Truth tests sometimes need to
test equality against the same reference to prove behavior. Generally ErrorProne will flag that as an error,
since it can never fail (and is therefore usually a badly written test) - Some docs on
OptionalSubject
updated relating to complex assertions. - Fix some sample code containing a bug.
For details, see the complete list of included commits.
Truth 0.32
New Subjects
- OptionalIntSubject (in java8 extension)
- StreamSubject (in java8 extension)
Changes to existing Subjects and Core classes
- add
.hasValueThat()
methods to primitive optionals which chain to the appropriate subject ThrowableSubject.hasMessageThat()
which chains to StringSubject, in place ofhasMessage(String)
ThrowableSubject.hasCauseThat()
which chains to ThrowableSubject around the cause- make
isInstanceof()
and related methods abort hard, under-XdisableClassMetadata
. - Introduce
DelegatedVerbFactory
as a more powerful (but looser) alternative toSubjectFactory
- make
MultimapSubject
useusingCorrespondence()
to allow custom "Fuzzy" equality for contains ops. - Allow
usingExactEquality
on floating point subjects take Number subtypes, not just floating point types. - Allow one-arg isEqualTo() to be used for primitive arrays of floating point types, implementing an agreed
upon algorithm - Add
containsCell(Cell)
anddoesNotContainCell(Cell)
to TableSubject. - Include more readable hexadecimals when isEqualTo fails on a byte[].
New Extensions
- Protocol Buffers
- Support for lite and heavy (with proto-reflection) protocol buffers
- IterableProtoSubject
Fixes
- Make
asList()
chaining methods obeynamed()
Misc
- Code all formated with google-java-format
- some error-prone notified improvemetns
For details, see the complete list of included commits.