This is expected to throw out in a method annotated by
TestCycle
,
TestSuite
or
TestCase
to indicate the failures of a certain test level.
Indicates that the test failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals.
And it will get SAFS to log a message of type
AbstractLogFacility.TESTLEVEL_FAILED
, example as below:
<LOG_MESSAGE type='TESTLEVEL_FAILED' date='06-19-2018' time='10:15:41' >
<MESSAGE_TEXT><![CDATA[{"messages":[{"message":"benchFile.txt doesn't match actualFile.txt.","details":"detailed failure message.","type":"DIFF","errorTrace":{"declaringClass":"a.testcase.Cases1","methodName":"case3","fileName":"Cases1.java","lineNumber":58}}],"stackTrace":[],"suppressedExceptions":[]}]]></MESSAGE_TEXT>
</LOG_MESSAGE>
Below is an example to throw this exception with a single error in test case.
@TestCase
public void case3() throws SAFSTestLevelFailure{
if(!SeleniumPlus.VerifyFileToFile("benchFile.txt", "actualFile.txt")){
throw new SAFSTestLevelFailure("benchFile.txt doesn't match actualFile.txt.","detailed failure message.", "DIFF");
}
}
Below is an example to throw this exception with multiple errors in test case.
@TestCase
public void case4() throws SAFSTestLevelFailure{
SAFSTestLevelFailure testLevelException = new SAFSTestLevelFailure();
org.safs.model.Component nonExistGui = new org.safs.model.Component("FANTACY_GUI");
if(!Misc.IsComponentExists(nonExistGui)){
testLevelException.addFailure("IsComponentExists failed.", nonExistGui.getName()+" doesn't exist!", "NON_EXIST");
}
if(!SeleniumPlus.WaitForGUI(nonExistGui, 3)){
testLevelException.addFailure("WaitForGUI failed.", nonExistGui.getName()+" doesn't exist!", "TIMEOUT");
}
throw testLevelException;
}