예제 #1
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);
   }
 }
예제 #2
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);
      }
    }