About Truth
Truth is a Java test assertion framework that provides assertions/propositions to apply to objects-under-test. It is intended to be used with the JUnit test infrastructure, and can be used in the context of unit or integration tests.
Truth seeks to apply a fluent interface to testing, and was inspired by FEST, and is the main way that Google writes its android and java tests internally. Its goal is to allow for tests whose assertions are readable and match a quasi-english style, such as assertThat(someString).contains("some substring")
. More readable tests make for less error-prone tests.
Truth is an open-source project hosted at Github and is permissively licensed under Apache 2.0, and its main website can be found here.
v 0.29 - pushing towards 1.0
Newly Supported Types
- AtomicLongMap
Changes to existing Subjects and Core classes
- Preliminary versions of "Fuzzy Equality" for doubles/floats. See
DoublesSubject
for
new APIs, and we'll be updating the docs on fuzzy equality soon. - Prefer
isEqualTo
instead ofequals
since that is a method with a fairly precise
meaning in Java, and we were hijacking it. .equals() shouldn't be called on Subject
implementations. - Multidimensional Array support in
ObjectArraySubject
- Lots of renames and deprecations.
- SPI/API cleanup
- marking a lot of subjects or their methods final, or noting where we can't
- start making parts of the infrastructure more in line with the Open/Closed Principle
(final methods, etc.) - stop storing "failure message" in the
TestVerb
, part 1
New Extensions
An 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: RE2JSupport for
MessageLite
protocol buffers is also in extensions, but not released
in 0.29.
Fixes
- Some cleanups of generics
- Message improvements:
- Trim some stack trace of the obvious truth frames, to make it clearer where the
locus of error is. (i.e. who needs to see Subject.failComparing() in the stack trace?) - ThrowableSubject uses string comparision where reasonable (to take advantage of
JUnit'sComparisonFailure
) - fix BooleanSubject's handling of
null
in failure messaging - other message improvements
- Trim some stack trace of the obvious truth frames, to make it clearer where the
Miscellaneous
- Apply
@CheckReturnValue
across a wide range of methods (on by default).- Users are strongly advised to use error-prone in their builds, to ensure
that this is checked, and the compiler errors out when people fail to call the
following chained methods.
- Users are strongly advised to use error-prone in their builds, to ensure
- build and continuous test system fixes
- more recent upstream dependencies
- full formating of the codebase using google-java-format
- various improvements from error-prone
- improvements to the examples
- more flesh out some holes in the tests
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.