User Tools

Site Tools


junit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
junit [2018/12/18 12:00] – created kalaschnikowjunit [2020/03/11 08:40] (current) – kalaschnikow
Line 1: Line 1:
 +====== JUnit ======
  
 +[[JUnit 5]]
 +
 +
 +===== Articles =====
 +
 +[[JUnit Best Practices]] by Kyle Blaney
 +
 +
 +===== AssertJ =====
 +A better alternative to JUnit assertions is : [[http://joel-costigliola.github.io/assertj/|AssertJ]]
 +
 +Examples for ''Assertions.assertThat()'':
 +<code java>
 +assertThat(frodo.age).isEqualTo(33);
 +assertThat(frodo.getName()).isEqualTo("Frodo").isNotEqualTo("Frodon");
 +
 +assertThat(frodo).isIn(fellowshipOfTheRing);
 +assertThat(frodo).isIn(sam, frodo, pippin);
 +assertThat(sauron).isNotIn(fellowshipOfTheRing);
 +
 +assertThat(frodo).matches(p -> p.age > 30 && p.getRace() == HOBBIT);
 +assertThat(frodo.age).matches(p -> p > 30);
 +</code>
 +
 +Examples for ''BDDAssertions.then()'':
 +<code java>
 +then(frodo.age).isEqualTo(33);
 +then(frodo.getName()).isEqualTo("Frodo").isNotEqualTo("Frodon");
 +
 +then(frodo).isIn(fellowshipOfTheRing);
 +then(frodo).isIn(sam, frodo, pippin);
 +then(sauron).isNotIn(fellowshipOfTheRing);
 +
 +then(frodo).matches(p -> p.age > 30 && p.getRace() == HOBBIT);
 +then(frodo.age).matches(p -> p > 30);
 +</code>