Reputation: 1
Here's an example method explaining what I'd like to do.
public void myMethod(Method m){
report = new ExtentReports("filename");
test = report.startTest("testName");
String actual = "sssssss";
String expected = "xxxxxxxx";
// what I can do with AssertJ id have a nice readable test
assertThat(actual).isEqualTo(expected).withFailMessage("BOINK!");
// what I can do with ExtentReports
if (!actual.equals(expected)) test.log(LogStatus.FAIL, "BOINK");
// what I want to extend assertJ to do
assertThat(actual).isEqualTo(expected).extentLog(test, LogStatus.FAIL, "BOINK");
}
My question would be how to extend AssertJ with another action, the .extentLog(args) method? Thank you
Upvotes: 0
Views: 294
Reputation: 7066
There is no way to directly extend AssertJ as you suggest, it would mean modifying AssertJ core API.
One option is to wrap the assertj assertions with a lambda to catch the assertion error (if any), pass it to the extent reports to capture the error message (don't forget to rethrow the error to have a failing test).
Upvotes: 1