Skip to content

Commit

Permalink
Add a first UI test that checks for the failing toggles.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Oct 24, 2023
1 parent 162c548 commit 5709756
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 89 deletions.
3 changes: 3 additions & 0 deletions plugin/src/main/resources/coverage/configuration.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<f:textbox/>
</f:entry>

<f:entry field="ignoreParsingErrors">
<f:checkbox title="${%title.ignoreParsingErrors}"/>
</f:entry>
<f:entry field="failOnError">
<f:checkbox title="${%failOnError.title}"/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ checksName.title=Checks name
checksAnnotationScope.title=Select the scope of source code annotations
failOnError.title=Fail the step if errors have been reported during the execution
title.enabledForFailure=Enable recording for failed builds
title.ignoreParsingErrors=Ignore parsing errors during processing of the coverage reports
title.skipSymbolicLinks=Skip symbolic links when searching for files
sourceCodeRetention.title=Source Code Retention Strategy

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
This toggle determines if the coverage plugin should ignore parsing errors during processing of the coverage
reports or if it should fail fast with an exception. By default this toggle is disabled and the
reports or if it should fail fast with an exception. By default, this toggle is disabled and the
parsers will fail fast. This helps to identify bugs in the parser or in the coverage tool execution.
If you would rather like to ignore parsing errors, please tick this checkbox. Please note, that in this
If you would rather like to ignore parsing errors, please tick this checkbox. Please note that in this
case the parser results might be incomplete or even wrong.
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
This toggle determines if the coverage plugin should ignore parsing errors during processing of the coverage
reports or if it should fail fast with an exception. By default this toggle is disabled and the
reports or if it should fail fast with an exception. By default, this toggle is disabled and the
parsers will fail fast. This helps to identify bugs in the parser or in the coverage tool execution.
If you would rather like to ignore parsing errors, please tick this checkbox. Please note, that in this
If you would rather like to ignore parsing errors, please tick this checkbox. Please note that in this
case the parser results might be incomplete or even wrong.
</div>
1 change: 0 additions & 1 deletion ui-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
<reuseForks>false</reuseForks>
<trimStackTrace>false</trimStackTrace> <!-- SUREFIRE-1798 -->
<environmentVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.jenkins.plugins.coverage.CoveragePublisher.Threshold;
package io.jenkins.plugins.coverage;

import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.PageArea;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.jenkins.plugins.coverage.CoveragePublisher;
package io.jenkins.plugins.coverage;

import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.PageArea;
import org.jenkinsci.test.acceptance.po.PageAreaImpl;

import io.jenkins.plugins.coverage.CoveragePublisher.Threshold.AdapterThreshold;
import io.jenkins.plugins.coverage.CoveragePublisher.Threshold.AdapterThreshold.AdapterThresholdTarget;
import io.jenkins.plugins.coverage.AdapterThreshold.AdapterThresholdTarget;

/**
* Adapter which can be added in the configuration of the {@link CoveragePublisher} of a FreeStyle Project.
Expand Down Expand Up @@ -96,4 +95,4 @@ public void ensureAdvancedOptionsIsActivated() {
public void deleteAdapter() {
this.delete.click();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package io.jenkins.plugins.coverage.CoveragePublisher.Threshold;

import io.jenkins.plugins.coverage.CoveragePublisher.Adapter;
import io.jenkins.plugins.coverage.CoveragePublisher.CoveragePublisher;
package io.jenkins.plugins.coverage;

/**
* Threshold used in {@link Adapter} in {@link CoveragePublisher}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.jenkins.plugins.coverage.util;
package io.jenkins.plugins.coverage;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.jenkins.plugins.coverage.CoveragePublisher;
package io.jenkins.plugins.coverage;

import org.jenkinsci.test.acceptance.po.AbstractStep;
import org.jenkinsci.test.acceptance.po.Control;
Expand All @@ -8,13 +8,12 @@
import org.jenkinsci.test.acceptance.po.PageAreaImpl;
import org.jenkinsci.test.acceptance.po.PostBuildStep;

import io.jenkins.plugins.coverage.CoveragePublisher.Threshold.GlobalThreshold;
import io.jenkins.plugins.coverage.CoveragePublisher.Threshold.GlobalThreshold.GlobalThresholdTarget;
import io.jenkins.plugins.coverage.GlobalThreshold.GlobalThresholdTarget;

/**
* Coverage Publisher which can be added in the configuration of a FreeStyle Project.
*/
@Describable("Record Code Coverage Results")
@Describable("Record code coverage results")
public class CoveragePublisher extends AbstractStep implements PostBuildStep {

private final Control adapter = control("hetero-list-add[adapters]");
Expand All @@ -25,29 +24,60 @@ public class CoveragePublisher extends AbstractStep implements PostBuildStep {
private final Control failNoReports = control("failNoReports");
private final Control failBuildIfCoverageDecreasedInChangeRequest = control(
"failBuildIfCoverageDecreasedInChangeRequest");
private final Control skipPublishingChecks = control("skipPublishingChecks");
private final Control sourceFileResolver = control("sourceFileResolver/level");
private final Control globalThreshold = control("repeatable-add");
private final Control sourceCodeEncoding = control("sourceCodeEncoding");
private final Control sourceDirectories = findRepeatableAddButtonFor("sourceDirectories");

private final Control id = control("id");
private final Control name = control("name");
private final Control skipPublishingChecks = control("skipPublishingChecks");
private final Control checksName = control("checksName");
private final Control checksAnnotationScope = control("checksAnnotationScope");
private final Control ignoreParsingErrors = control("ignoreParsingErrors");
private final Control failOnError = control("failOnError");
private final Control enabledForFailure = control("enabledForFailure");
private final Control skipSymbolicLinks = control("skipSymbolicLinks");
private final Control scm = control("scm");
private final Control sourceCodeEncoding = control("sourceCodeEncoding");
private final Control sourceCodeRetention = control("sourceCodeRetention");

/**
* Constructor for CoveragePublisher.
* Creates a new page object for the {@link CoveragePublisher}.
*
* @param parent
* is the job which uses the CoveragePublisher
* the parent job
* @param path
* on the parent page
* the path on the configuration page
*/
public CoveragePublisher(final Job parent, final String path) {
super(parent, path);
}

CoveragePublisher setIgnoreParsingErrors(final boolean ignoreParsingErrors) {
ensureAdvancedOptionsIsActivated();
this.ignoreParsingErrors.check(ignoreParsingErrors);

return this;
}

CoveragePublisher setFailOnError(final boolean failOnError) {
ensureAdvancedOptionsIsActivated();
this.failOnError.check(failOnError);

return this;
}

private Control findRepeatableAddButtonFor(final String propertyName) {
return control(by.xpath("//div[@id='" + propertyName + "']//button[contains(@path,'-add')]"));
}

CoveragePublisher setTool(final String tool, final String pattern) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'tool' is never used.
var tools = new CoverageTool(this, "tools");
tools.setTool("COBERTURA").setPattern(pattern);

return this;
}

/**
* Sets the encoding when reading source code files.
*
Expand Down Expand Up @@ -161,9 +191,9 @@ public void setChecksName(final String checksName) {
}

/**
* Ensures advanced options of CoveragePublisher is activated, so that values like {@link
* CoveragePublisher#setFailUnhealthy(boolean)} or {@link CoveragePublisher#setFailNoReports(boolean)} are visible
* and can be set.
* Ensures advanced options of CoveragePublisher is activated, so that values like
* {@link CoveragePublisher#setFailUnhealthy(boolean)} or {@link CoveragePublisher#setFailNoReports(boolean)} are
* visible and can be set.
*/
public void ensureAdvancedOptionsIsActivated() {
if (advancedOptions.exists()) {
Expand Down Expand Up @@ -278,6 +308,45 @@ public void setPath(final String path) {
this.path.set(path);
}
}

/**
* Page area of a coverage tool configuration.
*/
public static class CoverageTool extends PageAreaImpl {
private final Control tool = control("");
private final Control pattern = control("pattern");

CoverageTool(final PageArea coverageRecorder, final String path) {
super(coverageRecorder, path);
}

/**
* Sets the name of the tool.
*
* @param toolName
* the name of the tool, e.g., PIT, JACOCO, COBERTURA
*
* @return this
*/
public CoverageTool setTool(final String toolName) {
tool.select(toolName);
return this;
}

/**
* Sets the pattern of the files to parse.
*
* @param pattern
* the pattern
*
* @return this
*/
public CoverageTool setPattern(final String pattern) {
this.pattern.set(pattern);

return this;
}
}
}

Check warning on line 350 in ui-tests/src/main/java/io/jenkins/plugins/coverage/CoveragePublisher.java

View check run for this annotation

ci.jenkins.io / PMD

TooManyFields

NORMAL: Too many fields.
Raw output
Classes that have too many fields can become unwieldy and could be redesigned to have fewer fields, possibly through grouping related fields in new objects. For example, a class with individual city/state/zip fields could park them within a single Address field. <pre> <code> public class Person { // too many separate fields int birthYear; int birthMonth; int birthDate; float height; float weight; } public class Person { // this is more manageable Date birthDate; BodyMeasurements measurements; } </code> </pre> <a href="https://pmd.github.io/pmd-6.55.0/pmd_rules_java_design.html#toomanyfields"> See PMD documentation. </a>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.PageObject;

import static io.jenkins.plugins.coverage.util.ChartUtil.*;
import static io.jenkins.plugins.coverage.ChartUtil.*;

/**
* {@link PageObject} representing the Coverage Report.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package io.jenkins.plugins.coverage.CoveragePublisher.Threshold;

import io.jenkins.plugins.coverage.CoveragePublisher.CoveragePublisher;
package io.jenkins.plugins.coverage;

/**
* Global Threshold used in {@link CoveragePublisher}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import org.jenkinsci.test.acceptance.po.Job;
import org.jenkinsci.test.acceptance.po.PageObject;

import io.jenkins.plugins.coverage.util.ChartUtil;

/**
* {@link PageObject} representing the Job status on the build page of a job.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.jenkins.plugins.coverage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.junit.Ignore;
import org.junit.Test;

import org.jenkinsci.test.acceptance.junit.WithPlugins;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;

import io.jenkins.plugins.coverage.CoveragePublisher.CoveragePublisher.SourceFileResolver;
import io.jenkins.plugins.coverage.CoveragePublisher.SourceFileResolver;

import static org.assertj.core.api.AssertionsForClassTypes.*;

Expand All @@ -16,6 +20,45 @@
* results.
*/
public class CoveragePublisherTest extends UiTest {
/**
* Creates two successful builds. Tests the reference values in summary, coverage report and main panel.
*/
@Test
public void testCodeCoveragePlugin() {
FreeStyleJob job = getJobWithFirstBuildAndDifferentReports(InCaseCoverageDecreasedConfiguration.DONT_FAIL);
Build secondBuild = buildSuccessfully(job);

HashMap<String, Double> expectedCoverageFifthBuild = new HashMap<>();
expectedCoverageFifthBuild.put("Line", 91.02);
expectedCoverageFifthBuild.put("Branch", 93.97);
List<Double> expectedReferenceCoverageFifthBuild = new ArrayList<>();
expectedReferenceCoverageFifthBuild.add(-4.5);
expectedReferenceCoverageFifthBuild.add(5.38);

CoverageSummaryTest.verifySummaryWithReferenceBuild(secondBuild, expectedCoverageFifthBuild,
expectedReferenceCoverageFifthBuild);

CoverageReport report = new CoverageReport(secondBuild);
report.open();

FileCoverageTable fileCoverageTable = report.openFileCoverageTable();
CoverageReportTest.verifyFileCoverageTableContent(fileCoverageTable,
new String[] {"edu.hm.hafner.util", "edu.hm.hafner.util", "edu.hm.hafner.util"},
new String[] {"Ensure.java", "FilteredLog.java", "Generated.java"},
new String[] {"80.00%", "100.00%", "n/a"},
new String[] {"86.96%", "100.00%", "n/a"});
CoverageReportTest.verifyFileCoverageTableNumberOfMaxEntries(fileCoverageTable, 10);

String coverageTree = report.getCoverageTree();
CoverageReportTest.verifyCoverageTreeAfterSomeBuildsWithReports(coverageTree);

String coverageOverview = report.getCoverageOverview();
CoverageReportTest.verifyCoverageOverviewAfterSomeBuildsWithReports(coverageOverview);

MainPanel mainPanel = new MainPanel(job);
MainPanelTest.verifyTrendChartWithTwoReports(mainPanel, 1, 2);
}

/**
* Verifies that job with no report fails when setFailNoReports(true).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;

import io.jenkins.plugins.coverage.CoveragePublisher.Adapter;
import io.jenkins.plugins.coverage.CoveragePublisher.CoveragePublisher;
import io.jenkins.plugins.coverage.FileCoverageTable.Header;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;

import io.jenkins.plugins.coverage.CoveragePublisher.Adapter;
import io.jenkins.plugins.coverage.CoveragePublisher.CoveragePublisher;

import static org.assertj.core.api.Assertions.*;

/**
Expand Down
Loading

0 comments on commit 5709756

Please sign in to comment.