Home » Uncategorized » AssertJ – Lesbarere Tests mit vielen Zusatzfunktionen

AssertJ – Lesbarere Tests mit vielen Zusatzfunktionen

Based on: http://joel-costigliola.github.io/assertj/assertj-core-features-highlight.html#field-by-field

Contents

Cool 1: Fluent API ist gut lesbar

String name = "Hans";
assertThat(name).as("Der Name muss 'Hans' sein").isEqualTo("Hans");

Cool 2: Features wie z.B. Filtering

List<Person> persons = Arrays.asList(new Person(20, "Nora"), new Person(22, "Guliver"), new Person(66, "Siegfried"));
assertThat(persons).filteredOn("name", "Nora").extracting("name").containsOnly("Nora");

Cool 3: Soft Assertions – Mehrere assertions miteinander auswerten, bevor allenfalls abgebrochen wird

@Test
public void softAssertion(){

    List<Person> persons = Arrays.asList(new Person(20, "Nora"), new Person(22, "Guliver"), new Person(66, "Siegfried"));

    SoftAssertions.assertSoftly(softAssertions -> {
        softAssertions.assertThat(persons.size() > 8).as("Groesse der Personenliste").isTrue();
        softAssertions.assertThat(persons).as("Must be Reto having Noras Name?")
                        .filteredOn("name", "Nora").extracting("name").containsOnly("Reto");
            });
}

 

 


Hinterlasse einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert