diff --git a/src/main/java/hudson/tasks/junit/PackageResult.java b/src/main/java/hudson/tasks/junit/PackageResult.java index 3e0cc2bdf..c2188397c 100644 --- a/src/main/java/hudson/tasks/junit/PackageResult.java +++ b/src/main/java/hudson/tasks/junit/PackageResult.java @@ -201,7 +201,7 @@ public List getFailedTestsSortedByAge() { * @return the children of this test result, if any, or an empty collection */ @Override - public Collection getPassedTests() { + public List getPassedTests() { List r = new ArrayList(); for (ClassResult clr : classes.values()) { for (CaseResult cr : clr.getChildren()) { @@ -220,7 +220,7 @@ public Collection getPassedTests() { * @return the children of this test result, if any, or an empty list */ @Override - public Collection getSkippedTests() { + public List getSkippedTests() { List r = new ArrayList(); for (ClassResult clr : classes.values()) { for (CaseResult cr : clr.getChildren()) { diff --git a/src/main/java/hudson/tasks/junit/TestResult.java b/src/main/java/hudson/tasks/junit/TestResult.java index 5e0bbbc22..c20926173 100644 --- a/src/main/java/hudson/tasks/junit/TestResult.java +++ b/src/main/java/hudson/tasks/junit/TestResult.java @@ -81,7 +81,11 @@ public final class TestResult extends MetaTabulatedResult { */ private transient int totalTests; - private transient int skippedTests; + private transient List passedTests; + + private transient List skippedTests; + + private transient int skippedTestsCounter; private float duration; @@ -389,7 +393,7 @@ public int getFailCount() { @Exported(visibility=999) @Override public int getSkipCount() { - return skippedTests; + return skippedTestsCounter; } /** @@ -412,8 +416,19 @@ public List getFailedTests() { * @return the children of this test result, if any, or an empty collection */ @Override - public Collection getPassedTests() { - throw new UnsupportedOperationException(); // TODO: implement!(FIXME: generated) + public synchronized List getPassedTests() { + if(passedTests == null){ + passedTests = new ArrayList(); + for(SuiteResult s : suites) { + for(CaseResult cr : s.getCases()) { + if (cr.isPassed()) { + passedTests.add(cr); + } + } + } + } + + return passedTests; } /** @@ -422,8 +437,19 @@ public Collection getPassedTests() { * @return the children of this test result, if any, or an empty list */ @Override - public Collection getSkippedTests() { - throw new UnsupportedOperationException(); // TODO: implement!(FIXME: generated) + public synchronized List getSkippedTests() { + if(skippedTests == null){ + skippedTests = new ArrayList(); + for(SuiteResult s : suites) { + for(CaseResult cr : s.getCases()) { + if (cr.isSkipped()) { + skippedTests.add(cr); + } + } + } + } + + return skippedTests; } /** @@ -574,10 +600,12 @@ public void tally() { // TODO: free children? memmory leak? suitesByName = new HashMap(); failedTests = new ArrayList(); + skippedTests = null; + passedTests = null; byPackages = new TreeMap(); totalTests = 0; - skippedTests = 0; + skippedTestsCounter = 0; // Ask all of our children to tally themselves for (SuiteResult s : suites) { @@ -599,7 +627,7 @@ public void tally() { for (PackageResult pr : byPackages.values()) { pr.tally(); - skippedTests += pr.getSkipCount(); + skippedTestsCounter += pr.getSkipCount(); failedTests.addAll(pr.getFailedTests()); totalTests += pr.getTotalCount(); } @@ -620,6 +648,8 @@ public void freeze(TestResultAction parent) { suitesByName = new HashMap(); totalTests = 0; failedTests = new ArrayList(); + skippedTests = null; + passedTests = null; byPackages = new TreeMap(); } @@ -631,10 +661,18 @@ public void freeze(TestResultAction parent) { totalTests += s.getCases().size(); for(CaseResult cr : s.getCases()) { - if(cr.isSkipped()) - skippedTests++; - else if(!cr.isPassed()) + if(cr.isSkipped()) { + skippedTestsCounter++; + if (skippedTests != null) { + skippedTests.add(cr); + } + } else if(!cr.isPassed()) { failedTests.add(cr); + } else { + if(passedTests != null) { + passedTests.add(cr); + } + } String pkg = cr.getPackageName(), spkg = safe(pkg); PackageResult pr = byPackage(spkg); @@ -646,6 +684,14 @@ else if(!cr.isPassed()) Collections.sort(failedTests,CaseResult.BY_AGE); + if(passedTests != null) { + Collections.sort(passedTests,CaseResult.BY_AGE); + } + + if(skippedTests != null) { + Collections.sort(skippedTests,CaseResult.BY_AGE); + } + for (PackageResult pr : byPackages.values()) pr.freeze(); } diff --git a/src/main/java/hudson/tasks/junit/TestResultAction.java b/src/main/java/hudson/tasks/junit/TestResultAction.java index 8f3c65100..222f66a82 100644 --- a/src/main/java/hudson/tasks/junit/TestResultAction.java +++ b/src/main/java/hudson/tasks/junit/TestResultAction.java @@ -186,6 +186,17 @@ public List getFailedTests() { return getResult().getFailedTests(); } + @Override + public List getPassedTests() { + return getResult().getPassedTests(); + } + + @Override + public List getSkippedTests() { + return getResult().getSkippedTests(); + } + + /** * Loads a {@link TestResult} from disk. */ diff --git a/src/main/java/hudson/tasks/test/AbstractTestResultAction.java b/src/main/java/hudson/tasks/test/AbstractTestResultAction.java index 4f4d6b1f6..88b871922 100644 --- a/src/main/java/hudson/tasks/test/AbstractTestResultAction.java +++ b/src/main/java/hudson/tasks/test/AbstractTestResultAction.java @@ -36,6 +36,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; import jenkins.model.RunAction2; import jenkins.model.lazy.LazyBuildMixIn; import org.jfree.chart.ChartFactory; @@ -256,6 +257,28 @@ public List getFailedTests() { return Collections.emptyList(); } + /** + * A shortcut for scripting + * + * @return List of passed tests from associated test result. + * @since TODO + */ + @Nonnull + public List getPassedTests() { + return Collections.emptyList(); + } + + /** + * A shortcut for scripting + * + * @return List of skipped tests from associated test result. + * @since TODO + */ + @Nonnull + public List getSkippedTests() { + return Collections.emptyList(); + } + /** * Generates a PNG image for the test result trend. */