Reputation: 36
I’m using Citrus with TestNG
When execute this test (without citrus), Allure reports well a failure test
public class Ts_20X extends TestNGCitrusTestDesigner {
@Test
public void test1() {
Assert.assertEquals(2, 3);
}
}
But when I use Citrus to write this test, Allure reports a broken test
public class Ts_20Y extends TestNGCitrusTestDesigner
{
@Test
@Flaky
@CitrusTest
public void test3() {
fail("bad test");
}
}
Looking to the log, I can see these differences:
[ERROR] test1(Ts_20X) Time elapsed: 0.004 s <<< FAILURE!
java.lang.AssertionError: expected [3] but found [2]
Ts_20X.test1(Ts_20X.java:16)
[ERROR] test3(Ts_20Y) Time elapsed: 0.004 s <<< FAILURE!
com.consol.citrus.exceptions.TestCaseFailedException: bad test
Caused by: com.consol.citrus.exceptions.CitrusRuntimeException: bad test
It seems that Allure only put a failed status if the exception throwed is java.lang.AssertionError
With Citrus I have another exception so the test is broken.
As adding a try...catch
is not possible with Citrus testdesigner is there another solution to display a failed status to my Citrus test?
Thanks in advance.
Upvotes: 1
Views: 1193
Reputation: 36
A solution is to add a testNG Listener that catch specific error exceptions of Citrus and embeds the citrus error on a AssertionError.
@Override
public void onTestFailure(ITestResult result) {
logger.info("Test failed on Citrus framework");
logger.info("Test failed on "+result.getMethod().getMethodName());
String classError = result.getThrowable().getClass().getName();
switch (classError) {
case "com.consol.citrus.exceptions.TestCaseFailedException":
result.setStatus(ITestResult.FAILURE);
AssertionError errorCast = new AssertionError(
result.getThrowable().getMessage(),
result.getThrowable()
);
result.setThrowable(errorCast);
logger.info("TestCaseFailedException embedded into AssertionError");
break;
}
}
The Error will be considered as a AssertionError and will be displayed as Test Failed in Allure.
Upvotes: 1