Testing with Google Truth | Baeldung
Truth allows us to write readable assertions and failure messages for a variety of classes:
- Standard Java – primitives, arrays, strings, objects, collections, throwables, classes, etc.
- Java 8 – Optional and Stream instances
- Guava – Optional, Multimap, Multiset, and Table objects
- Custom types – by extending the Subject class, as we'll see later
Through the Truth and Truth8 classes, the library provides utility methods for writing assertions that work on a subject, that's the value or object under test.
Once the subject is known, Truth can reason at compile time about what propositions are known for that subject. This allows it to return wrappers around our value that declare proposition methods specific to that particular subject.
For example, when asserting on a list, Truth returns an IterableSubject instance defining methods like contains() and containsAnyOf(), among others. When asserting on a Map, it returns a MapSubject that declares methods like containsEntry() and containsKey().
Read full article from Testing with Google Truth | Baeldung
No comments:
Post a Comment