Skip to content

Using fest assertions

joel-costigliola edited this page · 6 revisions

(to main page)

FEST's assertions are incredibly easy to write: just type assertThat followed the actual value and a dot, and any Java IDE will show you all the assertions available for the type of the given object to verify. No more confusion about the order of the "expected" and "actual" values.
Our assertions are very readable as well: they read very close to plain English, making it easier for non-technical people to read test code.

Here are some examples:

import static org.fest.assertions.api.Assertions.*;

// common assertions

// String specific assertions

// collection specific assertions
                               .contains(frodo, sam)
// throwable specific assertions
try {
  fellowshipOfTheRing.get(9); // argggl !
} catch (Exception e) {
               .hasMessage("Index: 9, Size: 9")

// map specific assertions (One ring and elves ring bearers initialized before)
                       .includes(entry(oneRing, frodo), entry(nenya, galadriel))
                       .excludes(entry(oneRing, aragorn));

Fest provides assertions for the following data types:

  • Object
  • String
  • Date
  • Primitives (boolean, int, char, etc.)
  • BigDecimal
  • Iterable
  • Arrays of Object
  • Arrays of primitives
  • Map
  • Throwable
  • File and InputStream
  • BufferedImage

See our Tips and tricks page for best practices !

Something went wrong with that request. Please try again.