public void assertion(String status, IAssert assertCommand) { String expected = assertCommand.getExpected().toString(); String actual = assertCommand.getActual().toString(); String msg = assertCommand.getMessage(); if (expected != null) { seltest.info("|-{} :- EXPECTED = '{}' , ACTUAL = '{}' ", status, expected, actual); report.reportAssert("ASSERT " + status.toLowerCase(), expected,actual); } else if (msg != null) { seltest.info("|-{} :- Message : {} ", status, msg); report.reportAssert("ASSERT " + status.toUpperCase(), msg, ""); } else { seltest.info("|-{} ", status); report.reportAssert("ASSERT " + status.toUpperCase(), "", ""); } }
public void assertAll() { if (!m_errors.isEmpty()) { StringBuilder sb = new StringBuilder( "The following asserts failed:\n"); boolean first = true; for (Map.Entry<AssertionError, IAssert> ae : m_errors.entrySet()) { if (first) { first = false; } else { sb.append(", "); } sb.append(ae.getValue().getMessage()); } throw new SkipException("Verification Failures : " + sb.toString()); } }
public <T> void assertThat(final T actual, final Matcher<? super T> matcher) { doAssert(new IAssert() { @Override public void doAssert() { MatcherAssert.assertThat(actual, matcher); } @Override public Object getActual() { return actual; } @Override public Object getExpected() { return null; } @Override public String getMessage() { return null; } }); }
public <T> void assertThat(final String reason, final T actual, final Matcher<? super T> matcher) { doAssert(new IAssert() { @Override public void doAssert() { MatcherAssert.assertThat(reason, actual, matcher); } @Override public Object getActual() { return actual; } @Override public Object getExpected() { return null; } @Override public String getMessage() { return reason; } }); }
/** * Assert failures after test execution */ public void assertAll() { if (! m_errors.isEmpty()) { StringBuilder sb = new StringBuilder("The following asserts failed:\n"); boolean first = true; for (Map.Entry<AssertionError, IAssert> ae : m_errors.entrySet()) { if (first) { first = false; } else { sb.append(", "); } sb.append(ae.getKey()); } //set the test as failed Reporter.getCurrentTestResult().setStatus(ITestResult.FAILURE); org.testng.Reporter.setCurrentTestResult(Reporter.getCurrentTestResult()); m_errors.clear(); } }
@Override public void executeAssert(IAssert a) { errorsRetrieved = new HashMap<>(); try { a.doAssert(); } catch (AssertionError ex) { onAssertFailure(a, ex); errorsRetrieved.put(ex, a); } }
@Override public void executeAssert(IAssert a) { try { report.reportAssert("VERIFY : " + a.getMessage(), a .getExpected().toString(), a.getActual().toString()); a.doAssert(); } catch (AssertionError ex) { onAssertFailure(a, ex); // TODO Need to Remove 4 times logging m_errors.put(ex, a); } }
@Override public void executeAssert(IAssert a) { try { a.doAssert(); log.info("[EXPECTED]:"+a.getExpected()+" [ACTUAL]:"+ a.getActual()+"***** ----> VERIFICATION: "+a.getMessage(),"color:green; margin-left:20px;"); } catch(AssertionError ex) { log.verificationError("*****[EXPECTED]:"+a.getExpected()+" [ACTUAL]:"+ a.getActual()+"***** ----> VERIFICATION: "+a.getMessage()+ "------StackTrace:\\n"+findLineExceptionOccured(ex)); onAssertFailure(a, ex); m_errors.put(ex, a); } }
public Map<AssertionError, IAssert> getErrorsRetrieved() { return errorsRetrieved; }
@Override public void onAssertFailure(IAssert assertCommand, AssertionError ex) { logger.assertion(" (ASSERT FAILED) ", assertCommand); throw new AssertionError(ex); }
@Override public void onAssertSuccess(IAssert assertCommand) { logger.assertion(" (ASSERT SUCCESS) ", assertCommand); }
@Override public void onAfterAssert(IAssert assertCommand) { // Not Implemented }
@Override public void onBeforeAssert(IAssert assertCommand) { // Not Implemented }