-
Notifications
You must be signed in to change notification settings - Fork 69
One minute starting guide
Joel Costigliola edited this page Apr 15, 2012
·
37 revisions
Get the Fest Assertions 2.0M1 zip archive, then extract the jars to your classpath.
For Maven user, Fest artifacts are in Maven central repository
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M1</version>
</dependency>
Other dependencies coordinates (Ivy, Grape, ...) are described here.
import static org.fest.assertions.Assertions.*;
... and any Java IDE code completion will show you all the assertions available.
That's all !
Here are some examples:
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
// common assertions
assertThat(yoda).isInstanceOf(Jedi.class);
assertThat(frodo.getName()).isEqualTo("Frodo");
assertThat(frodo).isNotEqualTo(sauron);
assertThat(frodo).isIn(fellowshipOfTheRing);
assertThat(sauron).isNotIn(fellowshipOfTheRing);
// String specific assertions
assertThat(frodo.getName()).startsWith("Fro").endsWith("do")
.isEqualToIgnoringCase("frodo");
// collection specific assertions
assertThat(fellowshipOfTheRing).hasSize(9)
.contains(frodo, sam)
.excludes(sauron);
// throwable specific assertions
try {
fellowshipOfTheRing.get(9); // argggl !
} catch (Exception e) {
assertThat(e).isInstanceOf(IndexOutOfBoundsException.class)
.hasMessage("Index: 9, Size: 9")
.hasNoCause();
}
// map specific assertions (One ring and elves ring bearers initialized before)
assertThat(ringBearers).hasSize(4)
.includes(entry(Ring.oneRing, frodo), entry(Ring.nenya, galadriel))
.excludes(entry(Ring.oneRing, aragorn));
Have a direct look at fest-examples project sources, it covers what is possible with Fest Assertions. Or even better fork it and run it as JUnit tests ! Repo is here : fest-examples