Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 56 Next »

Welcome to the FEST Fluent Assertions Module

FEST-Assert is a Java library that provides a fluent interface for writing assertions. Its main goal is to improve test code readability and make maintenance of tests easier.

FEST-Assert requires Java SE 5.0 or later and can be used with either JUnit or TestNG.

Currently, this module provides assertions for the following data types:

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

It can be downloaded here. For Maven 2 users, details about the project's repository can be found at here.

We have written a migration guide to easily replace JUnit assertions with Fest assertions, check here.
Note that fest & junit assertions can coexist easily, you don't have to migrate all if you don't want to !

Examples

Some simple example to start.

More complete examples

The full example file is FestAssertExamples.java, you should be able to copy it in your IDE and run it successfully as JUnit tests.

Easy migration guide from JUnit assertions to Fest

Here's a list of find/replace based on regexp that allow to change JUnit assertion into Fest assertion (don't forget to check regexp mode in your editor replace window).
A similar idea would be to use the Strutured Search and Replace (SSR) feature of Intellij Idea.

Changing assertEquals(0, myList.size()) to assertThat(myList).isEmpty()

It's important to run this one before the assertEquals -> isEqualTo, to avoid ending with : assertThat(myList.size()).isEqualTo(0)

Changing assertEquals(expectedSize, myList.size()) to assertThat(myList).hasSize(expectedSize)

It's important to run this one before the assertEquals -> isEqualTo, to avoid ending with : assertThat(myList.size()).isEqualTo(expectedSize)

Changing assertEquals(value, valueUnderTest) to assertThat(valueUnderTest).isEqualTo(value)

Changing assertNotEquals(value, valueUnderTest) to assertThat(valueUnderTest).isNotEqualTo(value)

Changing assertNull(objectUnderTest) to assertThat(objectUnderTest).isNull()

Changing assertNotNull(objectUnderTest) to assertThat(objectUnderTest).isNotNull()

Changing assertTrue(logicalCondition) to assertThat(logicalCondition).isTrue()

Changing assertFalse(logicalCondition) to assertThat(logicalCondition).isFalse()

Custom Error Messages
Specifying custom error messages.

Extending
Extending FEST-Assert with custom conditions and assertions.

JUnit-Specific Features
FEST-Assert supports JUnit-specific features.

Comparing to Hamcrest
Comparing FEST-Assert and Hamcrest.

  • No labels