private void onFinishWebUITests(ITestContext testContext) {
    // List of test results which we will delete later because of duplication or because the test
    // eventually passed
    List<ITestResult> testsToBeRemoved = new ArrayList<ITestResult>();

    // collect all id's from passed test
    Set<Integer> passedTestIds = new HashSet<Integer>();
    for (ITestResult passedTest : testContext.getPassedTests().getAllResults()) {
      passedTestIds.add(getTestId(passedTest));
    }

    Set<Integer> failedTestIds = new HashSet<Integer>();
    for (ITestResult failedTest : testContext.getFailedTests().getAllResults()) {

      int failedTestId = getTestId(failedTest);
      // if this test failed before mark as to be deleted
      // or delete this failed test if there is at least one passed version
      if (failedTestIds.contains(failedTestId) || passedTestIds.contains(failedTestId)) {
        testsToBeRemoved.add(failedTest);
      } else {
        failedTestIds.add(failedTestId);
      }
    }
    // finally delete all tests that are marked
    for (Iterator<ITestResult> iterator = testContext.getFailedTests().getAllResults().iterator();
        iterator.hasNext(); ) {
      ITestResult testResult = iterator.next();
      if (testsToBeRemoved.contains(testResult)) {
        iterator.remove();
      }
    }
  }
Example #2
0
  protected static void process(File dir) throws IOException {
    File file = new File(dir, TESTS);
    if (!file.exists()) throw new IOException(file + " not found");
    List<TestCase> test_cases = new ArrayList<>();
    DataInputStream input = new DataInputStream(new FileInputStream(file));
    try {
      for (; ; ) {
        TestCase test_case = new TestCase();
        try {
          test_case.readFrom(input);
          test_cases.add(test_case);
        } catch (Exception e) {
          break;
        }
      }
    } finally {
      Util.close(input);
    }

    if (test_cases.isEmpty()) return;

    Reader stdout_reader = null, stderr_reader = null;
    File tmp = new File(dir, STDOUT);
    if (tmp.exists() && tmp.length() > 0) stdout_reader = new FileReader(tmp);

    tmp = new File(dir, STDERR);
    if (tmp.exists() && tmp.length() > 0) stderr_reader = new FileReader(tmp);
    File parent = dir.getParentFile();
    File xml_file = new File(parent, "TESTS-" + dir.getName() + "-" + parent.getName() + ".xml");
    Writer out = new FileWriter(xml_file);
    String classname = dir.getName();
    String suffix = parent.getName();
    if (suffix != null && !suffix.isEmpty()) classname = classname + "-" + suffix;
    try {
      generateReport(out, classname, test_cases, stdout_reader, stderr_reader);
    } finally {
      out.close();
      if (stdout_reader != null) stdout_reader.close();
      if (stderr_reader != null) stderr_reader.close();
    }
  }
Example #3
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");
    }
  }