Skip to content

Instantly share code, notes, and snippets.

@Rene-Frerichs
Last active November 6, 2015 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rene-Frerichs/bbc07e44f514e6d1e5fe to your computer and use it in GitHub Desktop.
Save Rene-Frerichs/bbc07e44f514e6d1e5fe to your computer and use it in GitHub Desktop.
AssertJ SoftAssertion
@Rule
public JUnitSoftAssertions softly = new JUnitSoftAssertions();
String openKnowledge = "offen, kundig, gut!";
@Test
public void exampleNormalAssertion() {
assertThat(openKnowledge).startsWith("kundig").endsWith("offen");
// -> java.lang.AssertionError: Expecting: <"offen, kundig, gut!"> to start with: <"kundig">
}
@Test
public void exampleSoftAssertion() {
softly.assertThat(openKnowledge).startsWith("kundig").endsWith("offen");
// -> java.lang.AssertionError: Expecting: <"offen, kundig, gut!"> to start with: <"kundig">
// -> java.lang.AssertionError: Expecting: <"offen, kundig, gut!"> to end with: <"offen">
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment