8. HAMCREST
assertThat(breizhCampSpeakers, hasSize(51));
• Vocabulaire plus riche
• Meilleure syntaxe
• Repose sur les Matcher
• Ne dépend pas du type
• Il faut connaitre le matcher à utiliser
9. FEST ASSERT
assertThat(breizhCampSpeakers).hasSize(51);
• Vocabulaire plus riche
• Meilleure syntaxe
• Repose sur les méthodes
• Dépend du type
• Découverte des méthodes par
10. ORIENTÉ SUR LE TYPE
• assertThat(XXX) => retourne un XXXAssert
• Différents
types supportés : ListAssert, StringAssert,
IntegerAssert, FileAssert, ThrowableAssert, ...
13. CONDITION
• Etendre l’existant
private final Condition<String> jedi = new Condition<String>("jedi") {
private final Set<String> jedis = set("Luke", "Yoda", "Obiwan");
@Override
public boolean matches(String value) {
return jedis.contains(value);
}
};
assertThat("Yoda").is(jedi);
assertThat("Vader").isNot(jedi);
assertThat("Yoda").has(jediPower);
assertThat("Solo").doesNotHave(jediPower);
14. ASSERTIONS
PERSONNALISÉES
• Propres aux objets métiers
public class TolkienCharacterAssert extends AbstractAssert<TolkienCharacterAssert, TolkienCharacter> {
public TolkienCharacterAssert(TolkienCharacter actual) {
super(actual, TolkienCharacterAssert.class);
}
public TolkienCharacterAssert hasName(String name) {
// check that actual TolkienCharacter we want to make assertions on is not null.
isNotNull();
// we overrides the default error message with a more explicit one
String errorMessage = format("Expected character's name to be <%s> but was <%s>", name, actual.getName());
// raw assertion : no WritableAssertionInfo usage - simpler but not friendly with custom comparison strategy (i.e.
usingComparator method)
if (!actual.getName().equals(name)) { throw new AssertionError(errorMessage); }
return this; // return the current assertion for method chaining
}
}
15. FEST ASSERT 2.0
• Ré-écriture complète
• En cours de développement (Actuellement M5)
• Vos idées sont les bienvenues
18. CONCLUSION
• Ne faite plus d’assertions avec JUnit ou TestNG
• Expressivité lisibilité
• Fest Assert fait partie du projet Fixtures for Easy Software
Testing. Il n’est pas seul :
A voir aussi Fest Reflect, Fest Swing