Aggregating Assertions - dn0000001/test-automation GitHub Wiki
There are times when you want a group of asserts to run before any failure occurs. (Normally, to gather more information to debug the failure.) Assertions do not allow this behaviour as execution stopped upon the 1st assertion failure.
However, to bypass this normal assertion behaviour, there is the AssertAggregator class. This class allows for execution of an entire group of asserts even if failures occur and after execution to fail.
Example:
AssertAggregator aggregator = new AssertAggregator();
// If running locally and not generating the report, then this will output the assertion failures to the console.
// It is not necessary to normal execution on jenkins.
aggregator.setConsole(true);
// Class has wrapped assertion methods such that way you write assertions remains the same.
// Any assertion can be converted by simply adding '**aggregator.**'
aggregator.assertThat("Street", actualStreet, equalTo(expectedStreet));
aggregator.assertThat("Full Address", actualFullAddress, startsWith(expectedFullStreet));
// Once all asserts in the group are executed, then trigger the validation.
// Note: It is necessary to use the Helper class to have any assertion failures written to report
Helper.assertThat(aggregator);