Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier for scripts to retrieve passed and skipped test results #24

Merged
merged 12 commits into from Dec 10, 2015
4 changes: 2 additions & 2 deletions src/main/java/hudson/tasks/junit/PackageResult.java
Expand Up @@ -201,7 +201,7 @@ public List<CaseResult> getFailedTestsSortedByAge() {
* @return the children of this test result, if any, or an empty collection
*/
@Override
public Collection<? extends hudson.tasks.test.TestResult> getPassedTests() {
public List<CaseResult> getPassedTests() {
List<CaseResult> r = new ArrayList<CaseResult>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change not going to break ABI compatibility for existing callers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an override, so it should be safe

for (ClassResult clr : classes.values()) {
for (CaseResult cr : clr.getChildren()) {
Expand All @@ -220,7 +220,7 @@ public Collection<? extends hudson.tasks.test.TestResult> getPassedTests() {
* @return the children of this test result, if any, or an empty list
*/
@Override
public Collection<? extends TestResult> getSkippedTests() {
public List<CaseResult> getSkippedTests() {
List<CaseResult> r = new ArrayList<CaseResult>();
for (ClassResult clr : classes.values()) {
for (CaseResult cr : clr.getChildren()) {
Expand Down
68 changes: 57 additions & 11 deletions src/main/java/hudson/tasks/junit/TestResult.java
Expand Up @@ -81,7 +81,11 @@ public final class TestResult extends MetaTabulatedResult {
*/
private transient int totalTests;

private transient int skippedTests;
private transient List<CaseResult> passedTests;

private transient List<CaseResult> skippedTests;

private transient int skippedTestsCounter;

private float duration;

Expand Down Expand Up @@ -389,7 +393,7 @@ public int getFailCount() {
@Exported(visibility=999)
@Override
public int getSkipCount() {
return skippedTests;
return skippedTestsCounter;
}

/**
Expand All @@ -412,8 +416,19 @@ public List<CaseResult> getFailedTests() {
* @return the children of this test result, if any, or an empty collection
*/
@Override
public Collection<? extends hudson.tasks.test.TestResult> getPassedTests() {
throw new UnsupportedOperationException(); // TODO: implement!(FIXME: generated)
public synchronized List<CaseResult> getPassedTests() {
if(passedTests == null){
passedTests = new ArrayList<CaseResult>();
for(SuiteResult s : suites) {
for(CaseResult cr : s.getCases()) {
if (cr.isPassed()) {
passedTests.add(cr);
}
}
}
}

return passedTests;
}

/**
Expand All @@ -422,8 +437,19 @@ public Collection<? extends hudson.tasks.test.TestResult> getPassedTests() {
* @return the children of this test result, if any, or an empty list
*/
@Override
public Collection<? extends hudson.tasks.test.TestResult> getSkippedTests() {
throw new UnsupportedOperationException(); // TODO: implement!(FIXME: generated)
public synchronized List<CaseResult> getSkippedTests() {
if(skippedTests == null){
skippedTests = new ArrayList<CaseResult>();
for(SuiteResult s : suites) {
for(CaseResult cr : s.getCases()) {
if (cr.isSkipped()) {
skippedTests.add(cr);
}
}
}
}

return skippedTests;
}

/**
Expand Down Expand Up @@ -574,10 +600,12 @@ public void tally() {
// TODO: free children? memmory leak?
suitesByName = new HashMap<String,SuiteResult>();
failedTests = new ArrayList<CaseResult>();
skippedTests = null;
passedTests = null;
byPackages = new TreeMap<String,PackageResult>();

totalTests = 0;
skippedTests = 0;
skippedTestsCounter = 0;

// Ask all of our children to tally themselves
for (SuiteResult s : suites) {
Expand All @@ -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();
}
Expand All @@ -620,6 +648,8 @@ public void freeze(TestResultAction parent) {
suitesByName = new HashMap<String,SuiteResult>();
totalTests = 0;
failedTests = new ArrayList<CaseResult>();
skippedTests = null;
passedTests = null;
byPackages = new TreeMap<String,PackageResult>();
}

Expand All @@ -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);
Expand All @@ -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();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/hudson/tasks/junit/TestResultAction.java
Expand Up @@ -186,6 +186,17 @@ public List<CaseResult> getFailedTests() {
return getResult().getFailedTests();
}

@Override
public List<CaseResult> getPassedTests() {
return getResult().getPassedTests();
}

@Override
public List<CaseResult> getSkippedTests() {
return getResult().getSkippedTests();
}


/**
* Loads a {@link TestResult} from disk.
*/
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/hudson/tasks/test/AbstractTestResultAction.java
Expand Up @@ -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;
Expand Down Expand Up @@ -256,6 +257,28 @@ public List<? extends TestResult> getFailedTests() {
return Collections.emptyList();
}

/**
* A shortcut for scripting
*
* @return List of passed tests from associated test result.
* @since TODO
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @since TODO and NonNull annotations

@Nonnull
public List<? extends TestResult> getPassedTests() {
return Collections.emptyList();
}

/**
* A shortcut for scripting
*
* @return List of skipped tests from associated test result.
* @since TODO
*/
@Nonnull
public List<? extends TestResult> getSkippedTests() {
return Collections.emptyList();
}

/**
* Generates a PNG image for the test result trend.
*/
Expand Down