org.testpackage.VisibleAssertions, which is a lightweight re-implementation of
VisibleAssertions augments the assertion errors it raises with a running commentary on standard out. Some of the API of
VisibleAssertions is summarised below.
Please note that TestPackage will generally suppress standard out unless a test fails, so you'd not normally expect to see this output on the command line for passing tests.
Aimed at simple boolean condition evaluation, although often
assertThat will yield more informative output. For example:
assertTrue("some boolean condition is as expected", myObject.isSomethingTrue()); assertTrue("another boolean condition is as expected", myBadObject.isSomethingTrue());
✔ some boolean condition is as expected ✘ another boolean condition is as expected
Tests two objects for equality, and describes the difference (as a toString()) if they are not equal. For example:
assertEquals("some thing is as expected", myExpectedObject, theActualObjectWhichIsEquals); assertEquals("some other thing is as expected", "my expected String", "the actual String");
✔ some thing is as expected ✘ some other thing is as expected 'the actual String' does not equal expected 'my expected String'
Brings the power of Hamcrest matchers to bear, and additionally uses the matchers to help construct an informative commentary. Rather than describing a condition, the first parameter can just be a noun describing the object which is being tested. For example:
assertThat("the thing", "a String", is(equalTo("a String"))); assertThat("the thing", "my actual String", is(equalTo("the expected String")));
✔ the thing is "a String" ✘ assertion on the thing failed asserted that it is "the expected String" but was "my actual String"
Other visible assertions methods follow similar patterns of usage and presentation style: