/** * {@inheritDoc} */ @Override public void afterInvocation(IInvokedMethod m, ITestResult tr) { isSuccess = tr.isSuccess(); }
private XMLReporterConfig.StackTraceLevels calculateStackTraceLevels(ITestResult testResult) { XMLReporterConfig.StackTraceLevels stackTraceoutputMethod = config.getStackTraceOutput(); if (testResult.isSuccess()) { stackTraceoutputMethod = config.getStackTraceOutputLevelForPassedTests(); } return stackTraceoutputMethod; }
private XMLReporterConfig.StackTraceLevels calculateStackTraceLevels(ITestResult testResult) { XMLReporterConfig.StackTraceLevels stackTraceoutputMethod = config.getStackTraceOutput(); if (testResult.isSuccess()) { stackTraceoutputMethod = config.getStackTraceOutputLevelForPassedTests(); } return stackTraceoutputMethod; }
@Override public boolean retry(final ITestResult iTestResult) { if (iTestResult.isSuccess()) { return false; } if (shouldRetry()) { count++; return true; } else { return false; } }
@AfterMethod(alwaysRun = true) public void endTestSuite(final Method method, final ITestResult result) throws Exception { if (hasFailed()) { return; } log.info("***************************************************************************************************"); log.info("*** Ending test {}:{} {} ({} s.)", new Object[]{method.getDeclaringClass().getName(), method.getName(), result.isSuccess() ? "SUCCESS" : "!!! FAILURE !!!", (result.getEndMillis() - result.getStartMillis()) / 1000}); log.info("***************************************************************************************************"); if (!hasFailed && !result.isSuccess()) { hasFailed = true; } }
/** * @return true if all the methods have been run successfully */ private boolean haveBeenRunSuccessfully(ITestNGMethod testMethod, ITestNGMethod[] methods) { // Make sure the method has been run successfully for (ITestNGMethod method : methods) { Set<ITestResult> results = keepSameInstances(testMethod, m_notifier.getPassedTests(method)); Set<ITestResult> failedAndSkippedMethods = Sets.newHashSet(); failedAndSkippedMethods.addAll(m_notifier.getFailedTests(method)); failedAndSkippedMethods.addAll(m_notifier.getSkippedTests(method)); Set<ITestResult> failedresults = keepSameInstances(testMethod, failedAndSkippedMethods); // If failed results were returned on the same instance, then these tests didn't pass if (failedresults != null && failedresults.size() > 0) { return false; } for (ITestResult result : results) { if(!result.isSuccess()) { return false; } } } return true; }
private boolean failuresPresentInUpstreamDependency(ITestNGMethod testMethod, ITestNGMethod[] methods) { // Make sure the method has been run successfully for (ITestNGMethod method : methods) { Set<ITestResult> results = keepSameInstances(testMethod, m_notifier.getPassedTests(method)); Set<ITestResult> failedAndSkippedMethods = Sets.newHashSet(); Set<ITestResult> skippedAttempts = m_notifier.getSkippedTests(method); failedAndSkippedMethods.addAll(m_notifier.getFailedTests(method)); failedAndSkippedMethods.addAll(skippedAttempts); Set<ITestResult> failedresults = keepSameInstances(testMethod, failedAndSkippedMethods); boolean wasMethodRetried = !results.isEmpty() && !skippedAttempts.isEmpty(); if (!wasMethodRetried && !failedresults.isEmpty()) { // If failed results were returned on the same instance, then these tests didn't pass return true; } for (ITestResult result : results) { if (!result.isSuccess()) { return true; } } } return false; }
@AfterMethod public void serializeRecord(ITestResult result) throws IOException { if (result.isSuccess() && result.getThrowable() == null) { /* Serialize the GenericRecord; this can catch issues in set() that the underlying GenericRecord * may not catch until serialize time */ DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(recordSchema); ByteArrayOutputStream bOs = new ByteArrayOutputStream(); BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(bOs, null); datumWriter.write(record, encoder); encoder.flush(); bOs.flush(); Assert.assertTrue(bOs.toByteArray().length > 0); } }
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(); } } }
private static Throwable getConfigFailureException(ITestContext context) { for (IInvokedMethod method : context.getSuite().getAllInvokedMethods()) { ITestNGMethod m = method.getTestMethod(); if (m.isBeforeSuiteConfiguration() && (!method.getTestResult().isSuccess())) { return method.getTestResult().getThrowable(); } } return null; }
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(); } } }
@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); } } }
private static Throwable getConfigFailureException(ITestContext context) { for (IInvokedMethod method : context.getSuite().getAllInvokedMethods()) { ITestNGMethod m = method.getTestMethod(); if (m.isBeforeSuiteConfiguration() && (!method.getTestResult().isSuccess())) { return method.getTestResult().getThrowable(); } } return null; } }
(result.getEndMillis() - result.getStartMillis()) / 1000}); log.info("***************************************************************************************************"); if (!hasFailed && !result.isSuccess()) {
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { try { if (testResult.isSuccess()) { boolean foundCache = false; CacheContext context = null;
/** * After test method. * * @param result test result */ @AfterMethod(alwaysRun = true) public void afterMethod(ITestResult result) { if (!result.isSuccess()) { failed(result.getThrowable(), result.getTestClass().getRealClass(), result.getName()); } finished(result.getTestClass().getRealClass(), result.getName()); }
@AfterMethod() public void afterMethod(ITestResult result){ if(!result.isSuccess()){ //Do stuff here if it failed } }
@AfterMethod(alwaysRun = true) public void afterMethodAlwaysRun(final Method method, final ITestResult result) throws Exception { log.info("***************************************************************************************************"); log.info("*** Ending test {}:{} {} ({} s.)", new Object[]{method.getDeclaringClass().getName(), method.getName(), result.isSuccess() ? "SUCCESS" : "!!! FAILURE !!!", (result.getEndMillis() - result.getStartMillis()) / 1000}); log.info("***************************************************************************************************"); if (!hasFailed && !result.isSuccess()) { hasFailed = true; } }
@AfterMethod(alwaysRun = true) public void endTestSuite(final Method method, final ITestResult result) throws Exception { log.info("***************************************************************************************************"); log.info("*** Ending test {}:{} {} ({} s.)", new Object[]{method.getDeclaringClass().getName(), method.getName(), result.isSuccess() ? "SUCCESS" : "!!! FAILURE !!!", (result.getEndMillis() - result.getStartMillis()) / 1000}); log.info("***************************************************************************************************"); if (!hasFailed && !result.isSuccess()) { hasFailed = true; } }