Ejemplo n.º 1
0
  protected void addTest(Class<?> clazz, ITestResult result) {
    try {
      TestCase test_case =
          new TestCase(
              result.getStatus(),
              clazz.getName(),
              getMethodName(result),
              result.getStartMillis(),
              result.getEndMillis());
      switch (result.getStatus()) {
        case ITestResult.FAILURE:
        case ITestResult.SKIP:
          Throwable ex = result.getThrowable();
          if (ex != null) {
            String failure_type = ex.getClass().getName();
            String failure_msg = ex.getMessage();
            String stack_trace = printException(ex);
            test_case.setFailure(failure_type, failure_msg, stack_trace);
          } else test_case.setFailure("exception", "SKIPPED", null);
          break;
      }

      synchronized (
          this) { // handle concurrent access by different threads, if test methods are run in
        // parallel
        DataOutputStream output = tests.get(clazz);
        test_case.writeTo(output);
      }
    } catch (Exception e) {
      error(e.toString());
    }
  }
Ejemplo n.º 2
0
 protected static String printException(Throwable ex) throws IOException {
   if (ex == null) return null;
   StackTraceElement[] stack_trace = ex.getStackTrace();
   StringBuilder sb = new StringBuilder();
   sb.append("\n<" + CDATA + "\n");
   sb.append(ex.getClass().getName() + " \n");
   for (int i = 0; i < stack_trace.length; i++) {
     StackTraceElement frame = stack_trace[i];
     sb.append("at " + frame.toString() + " \n");
   }
   sb.append("\n]]>");
   return sb.toString();
 }
Ejemplo n.º 3
0
 /** Generate the XML report from all the test results */
 protected void generateReports() throws IOException {
   File root_dir = new File(output_dir);
   if (!root_dir.exists()) throw new IOException(root_dir + " not found");
   File[] subdirs =
       root_dir.listFiles(
           new FileFilter() {
             public boolean accept(File f) {
               return f.isDirectory();
             }
           });
   if (subdirs != null) {
     for (File dir : subdirs) {
       try {
         process(dir);
       } catch (Throwable e) {
         error(e.toString());
       }
     }
   }
 }
Ejemplo n.º 4
0
  /** Generate the XML report from all the test results */
  protected static void generateReport(
      Writer out, String classname, List<TestCase> results, Reader stdout, Reader stderr)
      throws IOException {
    int num_failures = getFailures(results);
    int num_skips = getSkips(results);
    int num_errors = getErrors(results);
    long total_time = getTotalTime(results);

    try {
      out.write(XML_DEF + "\n");

      out.write(
          "\n<testsuite "
              + "name=\""
              + classname
              + "\" "
              + "tests=\""
              + results.size()
              + "\" "
              + "failures=\""
              + num_failures
              + "\" "
              + "errors=\""
              + num_errors
              + "\" "
              + "skips=\""
              + num_skips
              + "\" "
              + "time=\""
              + (total_time / 1000.0)
              + "\">");

      out.write("\n<properties>");
      Properties props = System.getProperties();

      for (Map.Entry<Object, Object> tmp : props.entrySet()) {
        out.write(
            "\n    <property name=\""
                + tmp.getKey()
                + "\""
                + " value=\""
                + tmp.getValue()
                + "\"/>");
      }
      out.write("\n</properties>\n");

      for (TestCase result : results) {
        if (result == null) continue;

        try {
          writeTestCase(out, result);
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }

      if (stdout != null) writeOutput(1, stdout, out);
      if (stderr != null) writeOutput(2, stderr, out);
    } finally {
      out.write("\n</testsuite>\n");
    }
  }