Skip to content

Commit

Permalink
JENKINS-42438 Correctly calculate test class duration.
Browse files Browse the repository at this point in the history
When running Android tests the <testsuite> in the generated xml file
can contain multiple classes.
Thus setting the test class duration to the value of the test-suite is wrong.

Instead the class duration is now calculated as sum its test cases.
This is the same way it was done before jenkinsci#35 was merged.
Reverting parts of both jenkinsci#35 and jenkinsci#54 did not break any existing tests.
  • Loading branch information
mfuchs committed Aug 18, 2017
1 parent d083744 commit 8e215f7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/main/java/hudson/tasks/junit/ClassResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Cumulative test result of a test class.
Expand Down Expand Up @@ -178,7 +176,7 @@ public void add(CaseResult r) {
@Override
public void tally() {
passCount=failCount=skipCount=0;
Set<SuiteResult> suites=new HashSet<SuiteResult>();
duration = 0;
for (CaseResult r : cases) {
r.setClass(this);
if (r.isSkipped()) {
Expand All @@ -190,13 +188,7 @@ else if(r.isPassed()) {
else {
failCount++;
}
suites.add( r.getSuiteResult() );
}

// retrieve the class duration from these cases' suite time
duration = 0;
for (SuiteResult s : suites) {
duration += s.getDuration();
duration += r.getDuration();
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/test/java/hudson/tasks/junit/TestResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,40 @@ public void testMergeWithoutTime() throws Exception {
assertEquals(30, suite.getDuration(), 2);
}

@Issue("JENKINS-42438")
@Test
public void testSuiteWithMultipleClasses() throws IOException, URISyntaxException {
TestResult testResult = new TestResult();
testResult.parse(getDataFile("JENKINS-42438/junit-report-1.xml"));
testResult.tally();

assertEquals("Wrong number of testsuites", 1, testResult.getSuites().size());
assertEquals("Wrong number of test cases", 11, testResult.getTotalCount());

// The suite duration is non-sensical for Android tests.
// This looks like a bug in the JUnit runner used by Android tests.
assertEquals("Wrong duration for test result", 2.0, testResult.getDuration(), 0.1);

SuiteResult suite = testResult.getSuite("org.catrobat.paintroid.test.integration.ActivityOpenedFromPocketCodeNewImageTest");
assertNotNull(suite);

assertEquals("Wrong number of test classes", 2, suite.getClassNames().size());

CaseResult case1 = suite.getCase("testDrawingSurfaceBitmapIsScreenSize");
assertNotNull(case1);
ClassResult class1 = case1.getParent();
assertNotNull(class1);
assertEquals("org.catrobat.paintroid.test.integration.BitmapIntegrationTest", class1.getFullName());
assertEquals("Wrong duration for test class", 5.0, class1.getDuration(),0.1);

CaseResult case2 = suite.getCase("testColorPickerDialogSwitchTabsInLandscape");
assertNotNull(case2);
ClassResult class2 = case2.getParent();
assertNotNull(class2);
assertEquals("org.catrobat.paintroid.test.integration.LandscapeTest", class2.getFullName());
assertEquals("Wrong duration for test class", 93.0, class2.getDuration(), 0.1);
}

private static final XStream XSTREAM = new XStream2();

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version='1.0' encoding='UTF-8' ?>
<testsuite name="org.catrobat.paintroid.test.integration.ActivityOpenedFromPocketCodeNewImageTest" tests="11" failures="0" errors="0" skipped="2" time="2.0" timestamp="2017-03-19T16:04:02" hostname="localhost">
<properties>
<property name="device" value="hudson_en-US_240_WVGA_android-18_x86(AVD) - 4.3.1" />
<property name="flavor" value="" />
<property name="project" value="Paintroid" />
</properties>
<testcase name="testDrawingSurfaceBitmapIsScreenSize" classname="org.catrobat.paintroid.test.integration.BitmapIntegrationTest" time="5.0" />
<testcase name="testCenterBitmapSimulateLoad" classname="org.catrobat.paintroid.test.integration.BitmapIntegrationTest" time="0.0">
<skipped />
</testcase>
<testcase name="testOpenColorPickerDialogChooseColorInLandscape" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="3.0" />
<testcase name="testToolBarOptionWidth" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="0.0">
<skipped />
</testcase>
<testcase name="testTools" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="0.0">
<skipped />
</testcase>
<testcase name="testColorPickerDialogSwitchTabsInLandscape" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="7.0" />
<testcase name="testOpenColorPickerDialogInLandscape" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="11.0" />
<testcase name="testLandscapeMode" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="13.0" />
<testcase name="testTopBarPosition" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="17.0" />
<testcase name="testBottomBarPosition" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="19.0" />
<testcase name="testToolBarOption" classname="org.catrobat.paintroid.test.integration.LandscapeTest" time="23.0" />
</testsuite>

0 comments on commit 8e215f7

Please sign in to comment.