From 6da8202b3f1b96f99024cea8d6abc4b165bf2369 Mon Sep 17 00:00:00 2001 From: Nir Gilboa Date: Sun, 17 Jun 2018 23:18:59 +0300 Subject: [PATCH 1/8] Add a list of all Skipped tests to the Test Result report --- .../java/hudson/tasks/junit/CaseResult.java | 73 ++++++++++++++----- .../tasks/test/MetaTabulatedResult.java | 15 ++-- .../tasks/junit/CaseResult/summary.jelly | 5 +- .../tasks/test/MetaTabulatedResult/body.jelly | 24 +++++- .../hudson/test/aggregated-failed-tests.jelly | 2 +- ...ailed-test.jelly => non-passed-test.jelly} | 26 +++---- 6 files changed, 104 insertions(+), 41 deletions(-) rename src/main/resources/lib/hudson/test/{failed-test.jelly => non-passed-test.jelly} (85%) diff --git a/src/main/java/hudson/tasks/junit/CaseResult.java b/src/main/java/hudson/tasks/junit/CaseResult.java index 10c479066..f8899535f 100644 --- a/src/main/java/hudson/tasks/junit/CaseResult.java +++ b/src/main/java/hudson/tasks/junit/CaseResult.java @@ -1,18 +1,18 @@ /* * The MIT License - * + * * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Daniel Dyer, Seiji Sogabe, Tom Huybrechts, Yahoo!, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -96,6 +96,13 @@ public class CaseResult extends TestResult implements Comparable { */ private /*final*/ int failedSince; + /** + * This test has been skipped since this build number (not id.) + * + * If {@link #isPassed() passing}, this field is left unused to 0. + */ + private /*final*/ int skippedSince; + private static float parseTime(Element testCase) { String time = testCase.attributeValue("time"); return new TimeToFloat(time).parse(); @@ -209,7 +216,7 @@ private static int halfMaxSize(Collection results) { public CaseResult(SuiteResult parent, String testName, String errorStackTrace) { this(parent, testName, errorStackTrace, ""); } - + public CaseResult(SuiteResult parent, String testName, String errorStackTrace, String errorDetails) { this.className = parent == null ? "unnamed" : parent.getName(); this.testName = testName; @@ -222,7 +229,7 @@ public CaseResult(SuiteResult parent, String testName, String errorStackTrace, S this.skipped = false; this.skippedMessage = null; } - + public ClassResult getParent() { return classResult; } @@ -363,12 +370,12 @@ public String getPackageName() { if(idx<0) return "(root)"; else return className.substring(0,idx); } - + @Override public String getFullName() { return className+'.'+getName(); } - + /** * @since 1.515 */ @@ -407,16 +414,42 @@ else if (getRun() != null) { this.failedSince = getRun().getNumber(); } else { LOGGER.warning("trouble calculating getFailedSince. We've got prev, but no owner."); - // failedSince will be 0, which isn't correct. + // failedSince will be 0, which isn't correct. } } return failedSince; } - + + /** + * If this test was skipped, then return the build number + * when this test was first skipped. + */ + @Exported(visibility=9) + public int getSkippedSince() { + // If we haven't calculated failedSince yet, and we should, + // do it now. + if (skippedSince==0 && getSkipCount()==1) { + CaseResult prev = getPreviousResult(); + if(prev!=null && !prev.isPassed()) + this.skippedSince = prev.getSkippedSince(); + else if (getRun() != null) { + this.skippedSince = getRun().getNumber(); + } else { + LOGGER.warning("trouble calculating getSkippedSince. We've got prev, but no owner."); + // skippedSince will be 0, which isn't correct. + } + } + return skippedSince; + } + public Run getFailedSinceRun() { return getRun().getParent().getBuildByNumber(getFailedSince()); } + public Run getSkippedSinceRun() { + return getRun().getParent().getBuildByNumber(getSkippedSince()); + } + /** * Gets the number of consecutive builds (including this) * that this test case has been failing. @@ -427,12 +460,14 @@ public Run getFailedSinceRun() { public int getAge() { if(isPassed()) return 0; - else if (getRun() != null) { + else if (isFailed() && getRun() != null) return getRun().getNumber()-getFailedSince()+1; + else if (isSkipped() && getRun() != null) { + return getRun().getNumber()-getSkippedSince()+1; } else { LOGGER.fine("Trying to get age of a CaseResult without an owner"); - return 0; - } + return 0; + } } /** @@ -452,7 +487,7 @@ else if (getRun() != null) { public String getStdout() { if(stdout!=null) return stdout; SuiteResult sr = getSuiteResult(); - if (sr==null) return ""; + if (sr==null) return ""; return getSuiteResult().getStdout(); } @@ -477,7 +512,7 @@ public CaseResult getPreviousResult() { if(pr==null) return null; return pr.getCase(getTransformedTestName()); } - + /** * Case results have no children * @return null @@ -486,7 +521,7 @@ public CaseResult getPreviousResult() { public TestResult findCorrespondingResult(String id) { if (id.equals(safe(getName()))) { return this; - } + } return null; } @@ -560,7 +595,7 @@ public boolean isPassed() { public boolean isSkipped() { return skipped; } - + /** * @return true if the test was not skipped and did not pass, false otherwise. * @since 1.520 @@ -629,7 +664,7 @@ public Run getRun() { public void setParentSuiteResult(SuiteResult parent) { this.parent = parent; - } + } public void freeze(SuiteResult parent) { this.parent = parent; @@ -689,7 +724,7 @@ public Status getStatus() { /*package*/ void setClass(ClassResult classResult) { this.classResult = classResult; } - + void replaceParent(SuiteResult parent) { this.parent = parent; } diff --git a/src/main/java/hudson/tasks/test/MetaTabulatedResult.java b/src/main/java/hudson/tasks/test/MetaTabulatedResult.java index b4e93e3e9..5bf13ac09 100644 --- a/src/main/java/hudson/tasks/test/MetaTabulatedResult.java +++ b/src/main/java/hudson/tasks/test/MetaTabulatedResult.java @@ -1,18 +1,18 @@ /* * The MIT License - * + * * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo!, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,7 +28,7 @@ /** * The purpose of this class is to provide a good place for the - * jelly to bind to. + * jelly to bind to. * {@link TabulatedResult} whose immediate children * are other {@link TabulatedResult}s. * @@ -41,4 +41,9 @@ public abstract class MetaTabulatedResult extends TabulatedResult { */ public abstract Collection getFailedTests(); + /** + * All skipped tests. + */ + public abstract Collection getSkippedTests(); + } diff --git a/src/main/resources/hudson/tasks/junit/CaseResult/summary.jelly b/src/main/resources/hudson/tasks/junit/CaseResult/summary.jelly index 25ce3acda..36b87e172 100644 --- a/src/main/resources/hudson/tasks/junit/CaseResult/summary.jelly +++ b/src/main/resources/hudson/tasks/junit/CaseResult/summary.jelly @@ -31,8 +31,8 @@ THE SOFTWARE. - - + +

${title} @@ -54,6 +54,7 @@ THE SOFTWARE. + diff --git a/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly b/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly index b99f42b29..900b53cc4 100644 --- a/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly +++ b/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly @@ -35,7 +35,7 @@ THE SOFTWARE. - + ${f.durationString} @@ -47,6 +47,28 @@ THE SOFTWARE. + +

${%All Skipped Tests}

+ + + + + + + + + + + + + +
${%Test Name}${%Duration}${%Age}
+ ${f.durationString} + + ${f.age} +
+
+

${%All Tests}

diff --git a/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly b/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly index c1e1d23ee..746ae4edf 100644 --- a/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly +++ b/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly @@ -52,7 +52,7 @@ THE SOFTWARE. - + diff --git a/src/main/resources/lib/hudson/test/failed-test.jelly b/src/main/resources/lib/hudson/test/non-passed-test.jelly similarity index 85% rename from src/main/resources/lib/hudson/test/failed-test.jelly rename to src/main/resources/lib/hudson/test/non-passed-test.jelly index 78e95215e..461c46093 100644 --- a/src/main/resources/lib/hudson/test/failed-test.jelly +++ b/src/main/resources/lib/hudson/test/non-passed-test.jelly @@ -25,19 +25,19 @@ THE SOFTWARE. - Display link to the failed test. + Display link to the test. @since 1.538 - Path to the failed test. + Path to the test. - Failed test object + Test object - - + + @@ -95,7 +95,7 @@ THE SOFTWARE. - - + @@ -57,7 +57,7 @@ THE SOFTWARE. - + diff --git a/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly b/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly index 746ae4edf..c1e1d23ee 100644 --- a/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly +++ b/src/main/resources/lib/hudson/test/aggregated-failed-tests.jelly @@ -52,7 +52,7 @@ THE SOFTWARE. - + diff --git a/src/main/resources/lib/hudson/test/non-passed-test.jelly b/src/main/resources/lib/hudson/test/failed-test.jelly similarity index 100% rename from src/main/resources/lib/hudson/test/non-passed-test.jelly rename to src/main/resources/lib/hudson/test/failed-test.jelly From c966bffedd72d3f6562cca1c46e321acb5eb722a Mon Sep 17 00:00:00 2001 From: Nir Gilboa Date: Thu, 16 May 2019 22:51:30 +0300 Subject: [PATCH 6/8] Method must be non-abstract to prevent issues with implementations predating it --- src/main/java/hudson/tasks/test/MetaTabulatedResult.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/tasks/test/MetaTabulatedResult.java b/src/main/java/hudson/tasks/test/MetaTabulatedResult.java index 5bf13ac09..4c9885fb1 100644 --- a/src/main/java/hudson/tasks/test/MetaTabulatedResult.java +++ b/src/main/java/hudson/tasks/test/MetaTabulatedResult.java @@ -25,6 +25,7 @@ import java.util.Collection; +import java.util.Collections; /** * The purpose of this class is to provide a good place for the @@ -44,6 +45,8 @@ public abstract class MetaTabulatedResult extends TabulatedResult { /** * All skipped tests. */ - public abstract Collection getSkippedTests(); + public Collection getSkippedTests() { + return Collections.emptyList(); + } } From ee98b7e05dfa76afb75cf9b68ad923bf5ec3ffec Mon Sep 17 00:00:00 2001 From: Nir Gilboa Date: Fri, 17 May 2019 15:04:15 +0300 Subject: [PATCH 7/8] Add recomputeSkippedSinceIfNeeded for consistency, fix typo --- .../java/hudson/tasks/junit/CaseResult.java | 19 +++++++++++-------- .../tasks/junit/TestResultLinksTest.java | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/hudson/tasks/junit/CaseResult.java b/src/main/java/hudson/tasks/junit/CaseResult.java index 2129d4f38..dc52c2ca1 100644 --- a/src/main/java/hudson/tasks/junit/CaseResult.java +++ b/src/main/java/hudson/tasks/junit/CaseResult.java @@ -427,14 +427,7 @@ else if (getRun() != null) { } } - - /** - * If this test was skipped, then return the build number - * when this test was first skipped. - */ - @Exported(visibility=9) - public int getSkippedSince() { - // If we haven't calculated skippedSince yet, and we should, do it now. + private void recomputeSkippedSinceIfNeeded() { if (skippedSince==0 && getSkipCount()==1) { CaseResult prev = getPreviousResult(); if(prev!=null && prev.isSkipped()){ @@ -447,6 +440,16 @@ else if (getRun() != null) { // skippedSince will be 0, which isn't correct. } } + } + + /** + * If this test was skipped, then return the build number + * when this test was first skipped. + */ + @Exported(visibility=9) + public int getSkippedSince() { + // If we haven't calculated skippedSince yet, and we should, do it now. + recomputeSkippedSinceIfNeeded(); return skippedSince; } diff --git a/src/test/java/hudson/tasks/junit/TestResultLinksTest.java b/src/test/java/hudson/tasks/junit/TestResultLinksTest.java index a33de6fdc..ae547574d 100644 --- a/src/test/java/hudson/tasks/junit/TestResultLinksTest.java +++ b/src/test/java/hudson/tasks/junit/TestResultLinksTest.java @@ -131,7 +131,7 @@ public void testPreviousBuildNotLoaded() throws IOException, URISyntaxException FreeStyleBuild build = new FreeStyleBuild(project) { @Override public FreeStyleBuild getPreviousBuild() { - fail("When no tests fail, we don't need tp load previous builds (expensive)"); + fail("When no tests fail, we don't need to load previous builds (expensive)"); return null; } }; From 45168acc5df83964bf3532acdf635acaa818598f Mon Sep 17 00:00:00 2001 From: Nir Gilboa Date: Fri, 31 May 2019 16:51:03 +0300 Subject: [PATCH 8/8] Skipped tests accessible with a link --- .../tasks/test/MetaTabulatedResult/body.jelly | 90 ++++++++++++++----- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly b/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly index 78c804c9f..b92907224 100644 --- a/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly +++ b/src/main/resources/hudson/tasks/test/MetaTabulatedResult/body.jelly @@ -25,6 +25,44 @@ THE SOFTWARE. + + + + +

${%All Failed Tests}

${f.durationString} ${f.age}
${f.durationString}
${f.durationString}
${f.durationString} ${f.age}
@@ -47,28 +85,6 @@ THE SOFTWARE.
- -

${%All Skipped Tests}

- - - - - - - - - - - - - -
${%Test Name}${%Duration}${%Age}
- ${f.durationString} - - ${f.age} -
-
-

${%All Tests}

@@ -117,4 +133,34 @@ THE SOFTWARE.
+ + + ${%Show all skipped tests} ${">>>"} +
+
+

${%All Skipped Tests}

+ + + + + + + + + + + + + +
${%Test Name}${%Duration}${%Age}
+ ${f.durationString} + + ${f.age} +
+
+
+
+