@Override public void runTestMethod(ITestResult tr) { try { invokeMethod(thisMethod, testInstance, parameters); } catch (Throwable t) { error[0] = t; tr.setThrowable(t); // make Throwable available to IHookable } }
@Override public void runConfigurationMethod(ITestResult tr) { try { invokeMethod(thisMethod, instance, parameters); } catch (Throwable t) { error[0] = t; tr.setThrowable(t); // make Throwable available to IConfigurable } }
private void throwConfigurationFailure(ITestResult testResult, Throwable ex) { testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); }
@Override public void runConfigurationMethod(ITestResult tr) { try { invokeMethod(thisMethod, instance, parameters); } catch (Throwable t) { error[0] = t; tr.setThrowable(t); // make Throwable available to IConfigurable } }
private void throwConfigurationFailure(ITestResult testResult, Throwable ex) { testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); }
@Override public void runTestMethod(ITestResult tr) { try { invokeMethod(thisMethod, testInstance, parameters); } catch (Throwable t) { error[0] = t; tr.setThrowable(t); // make Throwable available to IHookable } }
private static void invokeWithTimeoutWithNoExecutor(ITestNGMethod tm, Object instance, Object[] parameterValues, ITestResult testResult, IHookable hookable) { InvokeMethodRunnable imr = new InvokeMethodRunnable(tm, instance, parameterValues, hookable, testResult); long startTime = System.currentTimeMillis(); long realTimeOut = MethodHelper.calculateTimeOut(tm); try { imr.run(); if (System.currentTimeMillis() <= startTime + realTimeOut) { testResult.setStatus(ITestResult.SUCCESS); } else { ThreadTimeoutException exception = new ThreadTimeoutException("Method " + tm.getQualifiedName() + "()" + " didn't finish within the time-out " + realTimeOut); testResult.setThrowable(exception); testResult.setStatus(ITestResult.FAILURE); } } catch (Exception ex) { testResult.setThrowable(ex.getCause()); testResult.setStatus(ITestResult.FAILURE); } }
@Override public void testAssumptionFailure(Failure failure) { notified.add(failure.getDescription()); ITestResult tr = m_findedMethods.get(failure.getDescription()); validate(tr, failure.getDescription()); runAfterInvocationListeners(tr); tr.setStatus(TestResult.SKIP); tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); tr.setThrowable(failure.getException()); m_parentRunner.addSkippedTest(tr.getMethod(), tr); for (ITestListener l : m_listeners) { l.onTestSkipped(tr); } }
private void handleConfigurationFailure(Throwable ite, ITestNGMethod tm, ITestResult testResult, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, Object instance, XmlSuite suite) { Throwable cause= ite.getCause() != null ? ite.getCause() : ite; if(isSkipExceptionAndSkip(cause)) { testResult.setThrowable(cause); handleConfigurationSkip(tm, testResult, annotation, currentTestMethod, instance, suite); return; } Utils.log("", 3, "Failed to invoke configuration method " + tm.getQualifiedName() + ":" + cause.getMessage()); handleException(cause, tm, testResult, 1); runConfigurationListeners(testResult, false /* after */); // // If in TestNG mode, need to take a look at the annotation to figure out // what kind of @Configuration method we're dealing with // if (null != annotation) { recordConfigurationInvocationFailed(tm, testResult.getTestClass(), annotation, currentTestMethod, instance, suite); } }
protected static void invokeMethodConsideringTimeout(ITestNGMethod tm, ConstructorOrMethod method, Object targetInstance, Object[] params, ITestResult testResult) throws Throwable { if (MethodHelper.calculateTimeOut(tm) <= 0) { MethodInvocationHelper.invokeMethod(method.getMethod(), targetInstance, params); } else { MethodInvocationHelper.invokeWithTimeout(tm, targetInstance, params, testResult); if (!testResult.isSuccess()) { // A time out happened Throwable ex = testResult.getThrowable(); testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); throw testResult.getThrowable(); } } }
/** * An exception was thrown by the test, determine if this method * should be marked as a failure or as failure_but_within_successPercentage */ private void handleException(Throwable throwable, ITestNGMethod testMethod, ITestResult testResult, int failureCount) { if (throwable != null && testResult.getThrowable() == null) { testResult.setThrowable(throwable); } int successPercentage= testMethod.getSuccessPercentage(); int invocationCount= testMethod.getInvocationCount(); float numberOfTestsThatCanFail= ((100 - successPercentage) * invocationCount) / 100f; if(failureCount < numberOfTestsThatCanFail) { testResult.setStatus(ITestResult.SUCCESS_PERCENTAGE_FAILURE); } else { testResult.setStatus(ITestResult.FAILURE); } }
@Override public void testAssumptionFailure(Failure failure) { notified.add(failure.getDescription()); ITestResult tr = m_findedMethods.get(failure.getDescription()); validate(tr, failure.getDescription()); runAfterInvocationListeners(tr); tr.setStatus(TestResult.SKIP); tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); tr.setThrowable(failure.getException()); m_parentRunner.addSkippedTest(tr.getMethod(), tr); for (ITestListener l : m_listeners) { l.onTestSkipped(tr); } }
tr.setStatus(TestResult.FAILURE); tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); tr.setThrowable(failure.getException()); for (IConfigurationListener l : m_parentRunner.getConfigurationListeners()) { l.onConfigurationFailure(tr); tr.setStatus(TestResult.FAILURE); tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); tr.setThrowable(failure.getException()); m_parentRunner.addFailedTest(tr.getMethod(), tr); for (ITestListener l : m_listeners) {
protected static void invokeMethodConsideringTimeout( ITestNGMethod tm, ConstructorOrMethod method, Object targetInstance, Object[] params, ITestResult testResult) throws Throwable { if (MethodHelper.calculateTimeOut(tm) <= 0) { MethodInvocationHelper.invokeMethod(method.getMethod(), targetInstance, params); } else { MethodInvocationHelper.invokeWithTimeout(tm, targetInstance, params, testResult); if (!testResult.isSuccess()) { // A time out happened Throwable ex = testResult.getThrowable(); testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); throw testResult.getThrowable(); } } }
holder.status = ITestResult.SKIP; } else { testresult.setThrowable(exceptionsHolder.wrongException(ite)); holder.status = ITestResult.FAILURE; TestException exception = exceptionsHolder.noException(tm); if (exception != null) { testresult.setThrowable(exception); holder.status = ITestResult.FAILURE;
/** * An exception was thrown by the test, determine if this method should be marked as a failure or * as failure_but_within_successPercentage */ protected void handleException( Throwable throwable, ITestNGMethod testMethod, ITestResult testResult, int failureCount) { if (throwable != null && testResult.getThrowable() == null) { testResult.setThrowable(throwable); } int successPercentage = testMethod.getSuccessPercentage(); int invocationCount = testMethod.getInvocationCount(); float numberOfTestsThatCanFail = ((100 - successPercentage) * invocationCount) / 100f; if (failureCount < numberOfTestsThatCanFail) { testResult.setStatus(ITestResult.SUCCESS_PERCENTAGE_FAILURE); } else { testResult.setStatus(ITestResult.FAILURE); } }
private void failIfErrors(ITestResult result) { ErrorsCollector errorsCollector = SelenideLogger.removeListener(LISTENER_SOFT_ASSERT); if (errorsCollector != null) { try { errorsCollector.failIfErrors(result.getTestClass().getName() + '.' + result.getName()); } catch (AssertionError e) { result.setStatus(ITestResult.FAILURE); result.setThrowable(e); } } } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { try { if (testResult.isSuccess()) { for (Object param : testResult.getParameters()) { if (param instanceof SingleConsumerQueue<?>) { assertThat((SingleConsumerQueue<?>) param, is(validate())); } } } } catch (AssertionError caught) { testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(caught); } finally { cleanUp(testResult); } } }
testResult.setThrowable(new AssertionError(getTestName(method), testResult.getThrowable())); testResult.setThrowable(new AssertionError(getTestName(method), caught)); } finally { cleanUp(testResult);
exception.setStackTrace(stacktraces[0]); testResult.setThrowable(exception); testResult.setStatus(ITestResult.FAILURE); } else {