Java Code Examples for org.testng.ITestResult#isSuccess()

The following examples show how to use org.testng.ITestResult#isSuccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Retry.java    From AppiumTestDistribution with GNU General Public License v3.0 7 votes vote down vote up
@Override
public boolean retry(ITestResult iTestResult) {
    int maxRetryCount;
    RetryCount annotation = iTestResult.getMethod().getConstructorOrMethod().getMethod()
            .getAnnotation(RetryCount.class);
    if (annotation != null) {
        maxRetryCount = annotation.maxRetryCount();
    } else {
        try {
            maxRetryCount = MAX_RETRY_COUNT.getInt();
        } catch (Exception e) {
            maxRetryCount = 0;
        }
    }
    return !iTestResult.isSuccess() && COUNTER.incrementAndGet() < maxRetryCount;
}
 
Example 2
Source File: AvroGenericRecordAccessorTest.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 3
Source File: CacheValidationListener.java    From caffeine with Apache License 2.0 6 votes vote down vote up
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
  try {
    if (testResult.isSuccess()) {
      validate(testResult);
    } else {
      if (!detailedParams.get()) {
        detailedParams.set(true);
      }
      testResult.setThrowable(new AssertionError(getTestName(method), testResult.getThrowable()));
    }
  } catch (Throwable caught) {
    testResult.setStatus(ITestResult.FAILURE);
    testResult.setThrowable(new AssertionError(getTestName(method), caught));
  } finally {
    cleanUp(testResult);
  }
}
 
Example 4
Source File: SingleConsumerQueueTest.java    From caffeine with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 5
Source File: AbstractDifidoReporter.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
/**
 * In case the setup or teardown step failed, we would like to log the
 * exception as warning
 * 
 * @param testResult
 */
private void logIfFailureOccuredInConfiguration(ITestResult testResult) {
	if (!testResult.isSuccess()) {
		if (testResult.getThrowable() != null) {
			log(testResult.getThrowable().getMessage(), Arrays.toString(testResult.getThrowable().getStackTrace()),
					Status.warning, ElementType.regular);
		}
	}
}
 
Example 6
Source File: JavacTemplateTestBase.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 7
Source File: AbstractTest.java    From concurrentlinkedhashmap with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
public void validateIfSuccessful(ITestResult result) {
  try {
    if (result.isSuccess()) {
      for (Object param : result.getParameters()) {
        validate(param);
      }
    }
  } catch (AssertionError caught) {
    result.setStatus(ITestResult.FAILURE);
    result.setThrowable(caught);
  }
  initMocks(this);
}
 
Example 8
Source File: IConfigurationListenerCustom.java    From functional-tests-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationFailure(ITestResult iTestResult) {
    if (!iTestResult.getMethod().isTest() && !iTestResult.isSuccess()) {
        loggerBase.debug(iTestResult.getMethod().getMethodName());
        loggerBase.debug(iTestResult.getTestName());
        iTestResult.setStatus(ITestResult.FAILURE);
    }

    System.out.println("on configuration failure");

}
 
Example 9
Source File: LoggingTestCase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void after(ITestResult result) {
    if (!result.isSuccess()) {
        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add(context.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 10
Source File: TestLogger.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
private void deleteSuccessVideos(ITestResult result, String className) {
    if (result.isSuccess()
            && (null != System.getenv("KEEP_ALL_VIDEOS"))
            && !(System.getenv("KEEP_ALL_VIDEOS").equalsIgnoreCase("true"))) {
        File videoFile = new File(System.getProperty("user.dir")
                + FileLocations.ANDROID_SCREENSHOTS_DIRECTORY
                + AppiumDeviceManager.getAppiumDevice().getDevice().getUdid() + "/"
                + className + "/" + result.getMethod().getMethodName()
                + "/" + result.getMethod().getMethodName() + ".mp4");
        if (videoFile.exists()) {
            videoFile.delete();
        }
    }
}
 
Example 11
Source File: QuantumReportiumListener.java    From Quantum with MIT License 5 votes vote down vote up
private void logTestEnd(ITestResult testResult) {
	String endText = "TEST " + (testResult.isSuccess() ? "PASSED" : "FAILED") + ": ";
	addReportLink(testResult, getReportClient().getReportUrl());

	ConsoleUtils.logWarningBlocks(
			"REPORTIUM URL: " + getReportClient().getReportUrl().replace("[", "%5B").replace("]", "%5D"));
	ConsoleUtils.surroundWithSquare(endText + getTestName(testResult)
			+ (testResult.getParameters().length > 0 ? " [" + testResult.getParameters()[0] + "]" : ""));

}
 
Example 12
Source File: LoggingTestCase.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void after(ITestResult result) {
    if (!result.isSuccess()) {
        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add(context.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 13
Source File: LoggingTestCase.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void after(ITestResult result) {
    if (!result.isSuccess()) {
        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add(context.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 14
Source File: JavacTemplateTestBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 15
Source File: CacheValidationListener.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Free memory by clearing unused resources after test execution. */
private void cleanUp(ITestResult testResult) {
  boolean briefParams = !detailedParams.get();

  if (testResult.isSuccess() && briefParams) {
    testResult.setParameters(EMPTY_PARAMS);
    testResult.setThrowable(null);
  }

  Object[] params = testResult.getParameters();
  for (int i = 0; i < params.length; i++) {
    Object param = params[i];
    if ((param instanceof AsyncCache<?, ?>) || (param instanceof Cache<?, ?>)
        || (param instanceof Map<?, ?>) || (param instanceof Eviction<?, ?>)
        || (param instanceof Expiration<?, ?>) || (param instanceof VarExpiration<?, ?>)
        || ((param instanceof CacheContext) && briefParams)) {
      params[i] = simpleNames.get(param.getClass(), key -> ((Class<?>) key).getSimpleName());
    } else if (param instanceof CacheContext) {
      params[i] = simpleNames.get(param.toString(), Object::toString);
    } else {
      params[i] = Objects.toString(param);
    }
  }

  /*
  // Enable in TestNG 7.0
  if ((testResult.getName() != null) && briefParams) {
    testResult.setTestName(simpleNames.get(testResult.getName(), Object::toString));
  }
  */

  CacheSpec.interner.get().clear();
}
 
Example 16
Source File: BaseClassForTests.java    From xian with Apache License 2.0 5 votes vote down vote up
@Override
public boolean retry(ITestResult result)
{
    if ( result.isSuccess() || wasRetried )
    {
        wasRetried = false;
        return false;
    }

    wasRetried = true;
    System.err.println(String.format("Retry test 1 time. Name: %s - TestName: %s ", result.getName(), result.getTestName()));
    return true;
}
 
Example 17
Source File: LoggingTestCase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void after(ITestResult result) {
    if (!result.isSuccess()) {
        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add(context.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 18
Source File: JavacTemplateTestBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 19
Source File: LoggingTestCase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void after(ITestResult result) {
    if (!result.isSuccess()) {
        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add(context.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 20
Source File: JavacTemplateTestBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}