/**
   * Before invocation.
   *
   * @param methodtest the methodtest
   * @param result the result
   * @see org.testng.IInvokedMethodListener#beforeInvocation(org.testng.IInvokedMethod,
   *     org.testng.ITestResult)
   */
  @Override
  public final void beforeInvocation(final IInvokedMethod methodtest, final ITestResult result) {

    if (methodtest.isTestMethod()) {

      String dataProvider = "";

      Method method = methodtest.getTestMethod().getConstructorOrMethod().getMethod();
      Annotation[] testAnnot = method.getAnnotations();
      for (Annotation annot : testAnnot) {

        if (annot instanceof Test) {

          Test tAnnot = (Test) annot;
          dataProvider = tAnnot.dataProvider();
          if ("".equalsIgnoreCase(prevDataProvider)
              || !(prevDataProvider.equalsIgnoreCase(dataProvider))) {
            dataIteration = 0;
            prevDataProvider = dataProvider;
          }
        }
      }

      dataIteration++;
    }
  }
Esempio n. 2
0
 @Override
 public void onTestSuccess(ITestResult tr) {
   success++;
   String location =
       tr.getTestClass().getRealClass().getSimpleName() + '#' + tr.getMethod().getMethodName();
   try {
     Method realTestMethod = tr.getMethod().getMethod();
     Test specAssert = realTestMethod.getAnnotation(Test.class);
     if (specAssert != null
         && specAssert.description() != null
         && !specAssert.description().isEmpty()) {
       log("[SUCCESS] " + specAssert.description() + "(" + location + ")");
     } else {
       log("[SUCCESS] " + location);
     }
   } catch (IOException e) {
     throw new IllegalStateException("IO Error", e);
   }
 }
Esempio n. 3
0
    @Override
    public void onTestFailure(ITestResult tr) {
      failed++;
      count++;
      String location =
          tr.getTestClass().getRealClass().getSimpleName() + '#' + tr.getMethod().getMethodName();
      try {
        Method realTestMethod = tr.getMethod().getMethod();
        Test testAnnot = realTestMethod.getAnnotation(Test.class);
        if (testAnnot != null
            && testAnnot.description() != null
            && !testAnnot.description().isEmpty()) {
          if (tr.getThrowable() != null) {
            StringWriter sw = new StringWriter();
            PrintWriter w = new PrintWriter(sw);
            tr.getThrowable().printStackTrace(w);
            w.flush();
            log("[FAILED]  " + testAnnot.description() + "(" + location + "):\n" + sw.toString());
          } else {
            log("[FAILED]  " + testAnnot.description() + "(" + location + ")");
          }
        } else {

          if (tr.getThrowable() != null) {
            StringWriter sw = new StringWriter();
            PrintWriter w = new PrintWriter(sw);
            tr.getThrowable().printStackTrace(w);
            w.flush();
            log("[FAILED]  " + location + ":\n" + sw.toString());
          } else {
            log("[FAILED]  " + location);
          }
        }
      } catch (IOException e) {
        throw new IllegalStateException("IO Error", e);
      }
    }