コード例 #1
0
  /**
   * Summarize the last test results from the passed set of jobs, including the packages of the job.
   * If a job doesn't include any tests, add a 0 summary.
   *
   * @param jobs
   * @return
   */
  public static TestResultSummary getDetailedTestResultSummary(Collection<TopLevelItem> jobs) {
    TestResultSummary summary = new TestResultSummary();

    for (TopLevelItem item : jobs) {
      if (item instanceof Job) {
        Job job = (Job) item;

        // create summary for the last run
        Run run = job.getLastBuild();
        if (run != null) {
          TestResult testResult = TestUtil.getTestResult(job.getLastBuild());
          summary.addTestResult(testResult);

          AbstractTestResultAction tra = run.getAction(AbstractTestResultAction.class);

          if (tra != null) {
            if (tra.getResult() instanceof MetaTabulatedResult) {
              MetaTabulatedResult result = (MetaTabulatedResult) tra.getResult();

              // add test results for the packages
              for (hudson.tasks.test.TestResult child : result.getChildren()) {
                PackageResult sub =
                    new PackageResult(
                        child, child.getTotalCount(), child.getFailCount(), child.getSkipCount());
                testResult.getPackageResults().add(sub);
              }
            }
          }
        }
      }
    }

    return summary;
  }