@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) { if (method.isTestMethod() && testResult.getStatus() == SUCCESS) { try { getSoftAssert().assertAll(); } catch (AssertionError e) { testResult.getTestContext().getPassedTests().removeResult(testResult.getMethod()); testResult.setStatus(TestResult.FAILURE); testResult.setThrowable(e); } THREAD_LOCAL_CONTAINER_FOR_SOFT_ASSERTIONS.remove(); } }
/** * * @param result */ @Override public void onTestFailure(ITestResult result) { IRetryAnalyzer retryAnalyzer = result.getMethod().getRetryAnalyzer(); if(retryAnalyzer instanceof RetryTestAnalyzer){ RetryTestAnalyzer retryTestAnalyzer = (RetryTestAnalyzer) retryAnalyzer; if (retryTestAnalyzer.willRetry()) { result.setStatus(TestResult.SKIP); } } // RetryTestContext context = getRetryContext(result); // if (context != null) { // // IRetryAnalyzer retryAnalyzer = result.getMethod().getRetryAnalyzer(); // Assert.assertTrue(retryAnalyzer instanceof RetryTestAnalyzer, "RetryAnalyzer wasn't initialized first."); // RetryTestAnalyzer analyzer = (RetryTestAnalyzer) retryAnalyzer; // // // It's too late to change the TestResult Status in the Retry Analyzer so it // // must be set here. Feel free to set it to PASS if desired. // if (analyzer.willRetry()) { // result.setStatus(TestResult.SKIP); // } // } }
public void afterInvocation(final IInvokedMethod method, final ITestResult result) { Reporter.setCurrentTestResult(result); // Handle Soft CustomAssertion if (method.isTestMethod()) { final List<Throwable> verificationFailures = CustomAssertion.getVerificationFailures(); final int size = verificationFailures.size(); if (size == 0) { return; } else if (result.getStatus() == TestResult.FAILURE) { return; } result.setStatus(TestResult.FAILURE); if (size == 1) { result.setThrowable(verificationFailures.get(0)); } else { // create failure message with all failures and stack traces barring last failure) final StringBuilder failureMessage = new StringBuilder("!!! Many Test Failures (").append(size).append( ")\n"); for (int i = 0; i < size - 1; i++) { failureMessage.append("Failure ").append(i + 1).append(" of ").append(size).append("\n"); final Throwable t = verificationFailures.get(i); final String fullStackTrace = Utils.stackTrace(t, false)[1]; failureMessage.append(fullStackTrace).append("\n"); } // final failure final Throwable last = verificationFailures.get(size - 1); failureMessage.append("Failure ").append(size).append(" of ").append(size).append(":n"); failureMessage.append(last.toString()); // set merged throwable final Throwable merged = new Throwable(failureMessage.toString()); merged.setStackTrace(last.getStackTrace()); result.setThrowable(merged); } } }