Bot releases are visible (Hide)
Published by cpovirk over 6 years ago
Subject.failWithActual
and failWithoutActual
, which use the new Fact
class. (e06ca85f)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 delete named()
in favor of withMessage()
. (911c9394)failWithRawMessageAndCause
. Truth automatically attaches the cause if it's part of the assertion chain. If not, see the deprecation docs for the workaround. (3622e9cf)failComparing
. Use check("foo").that(actual().foo()).isEqualTo(expectedFoo)
. (2db2a4fa)fail*
methods. (1f9b2d63daaae2ecc49f9cd4b87d1bd84c71ba04)protected
method IterableSubject.failWithBadResultsAndSuffix()
(5becbfe5).ComparisonFailure
from MapSubject.containsEntry
. (4330ec62)ComparisonFailure
from assertThat(singleElementIterable).containsExactly(otherSingleElementIterable)
. (e44edd16)Runner
and Statement
frames from the stack trace. (d2bb0743)StringSubject.ignoringCase()
(13e80543)ignoringExtraRepeatedFieldElements()
to ProtoTruth. (f0702044)comparingExpectedFieldsOnly()
to ProtoTruth. (08908c17)MultimapSubject.containsExactly(Multimap)
. Use containsExactlyEntriesIn(Multimap)
. (containsExactly(Object k0, Object v0, Object... rest)
continues to exist.) (9c80ad50)isPartiallyOrdered()
methods. Use isOrdered()
(5becbfe5).IterableSubject.isNoneOf()
and isNotIn()
. (46c8d3d2)@NullableDecl
instead of jsr305 @Nullable
. Tools that read these annotations may need to be updated to recognize the new annotation. (10ee459c)Published by cpovirk over 6 years ago
check(String template, Object... args)
. Most users of check()
should migrate. If the new method doesn't suit your needs, please file a bug. (187a9699)getDisplaySubject()
, and marked actualCustomStringRepresentation()
as @ForOverride
. Callers should use actualAsString()
; overriders should use actualCustomStringRepresentation()
. (47ea976e, 24d4c960)assertThat(array).isEqualTo(otherArray)
compare arrays contents (not array identity) even when the input wasn't statically known to be an array. (ece35ace)Expect
to omit stack frames common to multiple failures. (48b31f74)named()
supplement the existing actual value text, not replace it. This brings it in line with other subjects' behaviors. (f4fabf2e)asList()
assertions. (df5c101a)isAnyOf
, isNone
, and isNotIn
to be more consistent. (6233d1b5)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 overriding isEqualTo()
, in which case we recommend delegating to super.isEqualTo()
when possible.) (7af9c567)actual.equals(null)
; all objects are assumed to be not equal to null
. (c1ab4ede)displayingDiffsPairedBy
to IterableOfProtosSubject
. (a51fc7ad)(Object expected, double tolerance)
overloads of isEqualTo()
and isNotEqualTo()
. (ca04f65b)@CompatibleWith
annotation from http://errorprone.info to isSameAs
, isNotSameAs
, isAnyOf
, and isNoneOf
. (24876516)assertThat(...).is{,Not}InstanceOf(SomeInterface.class)
blow up with a helpful message under GWT, rather than always fail in the case of isInstanceOf
and always succeed in the case of isNotInstanceOf
. (026d9229)assertThat(null).isInstanceOf(...)
fail()
under GWT instead of throw NullPointerException
. (026d9229)Published by cpovirk almost 7 years ago
FailureStrategy
to a one-method interface: fail(AssertionError)
, removing AbstractFailureStrategy
.Published by cpovirk almost 7 years ago
containsExactlyElementsIn()
and similar methods to accept arrays.Expect
support concurrent calls to fail()
.-target 7
. However, it continues to depend on only "Java-6-like" APIs so that it continues to work on old versions of Android. (16887362)double[]
equality. Also, changed the rendering of double[]
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. (1a4c6797)StandardSubjectBuilder.check()
final. (1d44b587)Published by cpovirk almost 7 years ago
Subject.failureStrategy
. Use Subject.fail*
.Truth.THROW_ASSERTION_ERROR
and TruthJUnit.throwAssumptionError()
. Use Truth.assert_()
and TruthJUnit.assume()
(and methods like fail()
and about(...).that(...)
on the resulting objects).SubjectFactory
and CustomSubjectBuilderFactory
. Use nested types Subject.Factory
and CustomSubjectBuilder.Factory
, which accept new type FailureMetadata
rather than FailureStrategy
.protected
now that they're useful only from subclasses.DefaultSubject
entirely: Use Subject
.Published by cpovirk about 7 years ago
*Verb*
types and associated classes (after migrating Proto-Truth).ExpectationGatherer
.Subject.failureStrategy
, introducing more Subject.fail*
methods to take its place.Truth.THROW_ASSERTION_ERROR
and TruthJUnit.throwAssumptionError()
. Users should use Truth.assert_()
and TruthJUnit.assume()
(and methods like fail()
and about(...).that(...)
on the resulting objects).SubjectFactory
and CustomSubjectBuilderFactory
, introducing nested types Subject.Factory
and CustomSubjectBuilder.Factory
to take their place. The nested types accept new type FailureMetadata
rather than FailureStrategy
, and our Subject
classes have been updated accordingly. The main benefit is that, once you update your Subject
constructors to accept FailureMetadata
, you can expose a Subject.Factory
, and it can usually be implemented with a method reference: return FooSubject::new
;.Published by cpovirk about 7 years ago
withFailureMessage
, the old name of withMessage
.assertAbout(...).withFailureMessage(...)
in favor of assertWithMessage(...).about(...)
.ExpectationGatherer
.*Verb*
types in favor of new *SubjectBuilder*
types.IntStream
and LongStream
.MultimapSubject.containsExactly()
method.Expect
. Primarily, make any given assertion call fail at most once.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.Published by cpovirk over 7 years ago
MultimapSubject.containsExactly
.withFailureMessage
to withMessage
(on AbstractVerb
/TestVerb
).assertAbout(...).withFailureMessage(...)
in favor of assertWithMessage(...).about(...)
.FailureStrategy
is fully abstract. Users should prefer AbstractFailureStrategy
or one of the alternatives detailed in the javadocs.Published by cgruber over 7 years ago
ExpectFailure
, a common mechanism for capturing failures in Truth, allowing tests to verify Truth failures without catching AssertionError
. Intended primarily for testing Subject
implementations.PrimitiveDoublesArraySubject.hasvaluesWithin()
andPrimitiveFloatArraySubject.hasvaluesWithin()
.AbstractFailureStrategy
; users creating their own custom FailureStrategy
implementations are encouraged to migrate to this class if possible.Subject.ignoreCheck()
which is similar to Subject.check()
but passes a no-op failure strategy, toExpect
).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.Protocol Buffers
LiteProtoTruth
docsassertThat(Double.NaN).isNaN()
in gwt/j2cl now working properly.ThrowableSubject
and Java8 Optional*Subject
tests now use ExpectFailure
which exposed some bad behavior, now fixed.IterableSubject
adds type information to errors when string representations are the same, to clarify someFailureStrategy
usage to prepare for FailureStrategy
becoming fully abstract@SuppressWarnings("TruthSelfEquals")
since Truth tests sometimes need toOptionalSubject
updated relating to complex assertions.For details, see the complete list of included commits.
Published by cgruber over 7 years ago
.hasValueThat()
methods to primitive optionals which chain to the appropriate subjectThrowableSubject.hasMessageThat()
which chains to StringSubject, in place of hasMessage(String)
ThrowableSubject.hasCauseThat()
which chains to ThrowableSubject around the causeisInstanceof()
and related methods abort hard, under -XdisableClassMetadata
.DelegatedVerbFactory
as a more powerful (but looser) alternative to SubjectFactory
MultimapSubject
use usingCorrespondence()
to allow custom "Fuzzy" equality for contains ops.usingExactEquality
on floating point subjects take Number subtypes, not just floating point types.containsCell(Cell)
and doesNotContainCell(Cell)
to TableSubject.asList()
chaining methods obey named()
For details, see the complete list of included commits.
Published by cgruber over 7 years ago
@SafeVarargs
to some methods where appropriateFor details, see the complete list of included commits.
Published by cgruber about 8 years ago
Truth8.assertThat(Optional<T>)
)Preliminary versions of "Fuzzy Equality" for doubles/floats. See DoublesSubject
for
new APIs, and we'll be updating the docs on fuzzy equality soon.
getSubject()
-> actual()
getDisplaySubject()
-> actualAsString()
actualCustomStringRepresentation()
can be overridden. The deprecatedgetDisplaySubject()
and getSubject()
methods should not be overridden (and will befinal
.actualAsString()
has logic that not only consumes the string representation (default or custom).named()
and other contextual formatting.More evolution of "Fuzzy" truth - near-value approximation for certain types rather than strict
equality is now supported by way of a "correspondence" mechanism, and the capabilities are
being extended to many existing subjects.
To use:
assertThat(actualIterable)
.comparingElementsUsing(correspondence)
.containsExactlyElementsIn(expectedIterable);
Currently supports containsExactlyElementsIn(Iterable<E>)
, doesNotContain(E)
, and
contains(E)
methods. Subjects for Map
, Iterable
, and the Multimap
types all support
correspondence. For more detail, see the javadoc for IterableSubject.UsingCorrespondence and
Correspondence
.named()
now supports a varargs/format construction, such as:
assertThat(someBooleanFunction())
.named("processed %s(%s)", foo, bar)
.isTrue();
This results in a more suitable error message: Not true that processed foo(bar) <false> is true
as
compared with the default message, and requires less string concatenation where that may prove
awkward
java.util.Optional
Include "com.google.truth.extensions:truth-java8-extension:0.30" in your build dependencies
To use:
import static com.google.common.truth.Truth8.assertThat;
import java.util.Optional;
public class MyTest {
@Test public void testOptional() {
Optional<String> o = Optional.of("Foo");
assertThat(o).isPresent(); //succeeds
assertThat(o).hasValue("Foo"); //succeeds
assertThat(o).isEmpty(); // fails
}
}
@Nullable
in AbstractVerb.that(T)Published by cgruber about 8 years ago
DoublesSubject
forisEqualTo
instead of equals
since that is a method with a fairly preciseObjectArraySubject
TestVerb
, part 1An extension/contrib submodule, for things we want to ship with Truth,
but which may need to be separate artifacts, mostly due to dependency
issues or general bloat. Including our first entry: RE2J
Support for
MessageLite
protocol buffers is also in extensions, but not released
in 0.29.
ComparisonFailure
)null
in failure messaging@CheckReturnValue
across a wide range of methods (on by default).
Note: various methods are being deprecated in preparation for 1.0. A penultimate
pre-1.0 release will be cut with those deprecated methods intact. Then a 1.0 will
be released with those methods removed. This should give people a chance to
get the 1.0 features and benefits, but have a nice transition phase.