-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathCoveragePublisherTest.java
More file actions
159 lines (135 loc) · 5.91 KB
/
CoveragePublisherTest.java
File metadata and controls
159 lines (135 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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.SourceFileResolver;
import static org.assertj.core.api.AssertionsForClassTypes.*;
/**
* Acceptance tests for CoveragePublisher. Verifies if set options in CoveragePublisher are used and lead to excepted
* 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).
*/
@Test
public void testFailOnNoReport() {
FreeStyleJob job = getJobWithoutAnyReports(InCaseNoReportsConfiguration.FAIL);
buildWithErrors(job);
}
/**
* Verifies that job with decreased coverage fails when setFailBuildIfCoverageDecreasedInChangeRequest(true).
*/
@Test
public void testFailOnDecreasedCoverage() {
FreeStyleJob job = getJobWithFirstBuildAndDifferentReports(InCaseCoverageDecreasedConfiguration.FAIL);
buildWithErrors(job);
}
/**
* Test if build fails if setFailUnhealthy is true and thresholds set.
*/
@Test
@Ignore("This bug needs to be fixed")
public void testAdapterThresholdsAndFailOnUnhealthySetter() {
FreeStyleJob job = getJobWithAdapterThresholdAndFailOnUnhealthySetter(97, 99, true, ThresholdLevel.ADAPTER);
buildWithErrors(job);
}
/**
* Test if global thresholds are set.
*/
@Test
public void testGlobalThresholdsAndFailSetter() {
FreeStyleJob job = getJobWithAdapterThresholdAndFailOnUnhealthySetter(97, 99, true, ThresholdLevel.GLOBAL);
buildUnstable(job);
}
/**
* Tests if source file storing level and display is correct.
*/
@Test
@WithPlugins("git")
public void testSourceFileStoringLevelAllBuilds() {
FreeStyleJob job = getJobWithReportAndSourceCode(SourceFileResolver.STORE_ALL_BUILD);
Build build = buildSuccessfully(job);
buildSuccessfully(job);
buildSuccessfully(job);
buildSuccessfully(job);
buildSuccessfully(job);
verifyClickableFileSelection(build, true);
}
/**
* Tests if source file is only available for last build.
*/
@Test
@WithPlugins("git")
public void testSourceFileStoringLevelLastBuild() {
FreeStyleJob job = getJobWithReportAndSourceCode(SourceFileResolver.STORE_LAST_BUIlD);
Build firstBuild = buildSuccessfully(job);
Build secondBuild = buildSuccessfully(job);
Build thirdBuild = buildSuccessfully(job);
verifyClickableFileSelection(firstBuild, false);
verifyClickableFileSelection(secondBuild, false);
verifyClickableFileSelection(thirdBuild, true);
}
/**
* Tests if source file storing is off.
*/
@Test
@WithPlugins("git")
public void testSourceFileStoringLevelNever() {
FreeStyleJob job = getJobWithReportAndSourceCode(SourceFileResolver.NEVER_STORE);
Build firstBuild = buildSuccessfully(job);
verifyClickableFileSelection(firstBuild, false);
}
/**
* Verifies if a file in a {@link FileCoverageTableRow} is clickable.
*
* @param build
* The current build with file coverage
* @param sourceCodeAvailable
* {@code true} if the source code is available and should be displayed
*/
private void verifyClickableFileSelection(final Build build, final boolean sourceCodeAvailable) {
CoverageReport report = new CoverageReport(build);
report.open();
FileCoverageTable fileCoverageTable = report.openFileCoverageTable();
FileCoverageTableRow row = fileCoverageTable.getRow(0);
row.openSourceCode();
assertThat(report.isExpectedSourceFileContentDisplayed(sourceCodeAvailable)).isEqualTo(sourceCodeAvailable);
}
}