- Notifications
You must be signed in to change notification settings - Fork 76
Integration test #266
Integration test #266
Conversation
| | ||
| WorkflowJob job2 = createPipelineWithWorkspaceFiles(JACOCO_LESS_FILE_NAME); | ||
| job2.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [jacocoAdapter('**/*.xml')]," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add the reference job finder:
discoverReferenceBuild(referenceJob: 'reference')
uhafner left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also check your coding style settings.
| | ||
| | ||
| @Rule | ||
| public JenkinsRule j = new JenkinsRule(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates another Jenkins instance per test. Remove it, it is already in the base class.
| WorkflowJob job = createPipelineWithWorkspaceFiles(JACOCO_FILE_NAME, JACOCO_LESS_FILE_NAME); | ||
| job.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [jacocoAdapter('**/*.xml')]" | ||
| + "}", true)); | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to find a way that you do not need to duplicate code in each test
| assertThat(build.getNumber()).isEqualTo(1); | ||
| | ||
| CoverageBuildAction coverageResult = build.getAction(CoverageBuildAction.class); | ||
| assertThat(coverageResult.getLineCoverage()).isEqualTo(new Coverage(12166, 12736-12166)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to use constants in the expressions for the whole test so this is better understandable. Something like JACOCO_LARGE_MISSED_LINES, JACOCO_SMLL_COVERES_LINE. Then you can let Java sum up these values for you.
| Run<?, ?> build = buildSuccessfully(job); | ||
| assertThat(build.getNumber()).isEqualTo(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY
| job.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [cobertura('**/*.xml')]" | ||
| + "}", true)); | ||
| | ||
| Run<?, ?> build = buildSuccessfully(job); | ||
| assertThat(build.getNumber()).isEqualTo(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, the code is almost identical
| public void CoveragePluginPipeline_1_CoberturaInputFile_1JacocoInputFile() throws IOException { | ||
| WorkflowJob job = createPipelineWithWorkspaceFiles(JACOCO_FILE_NAME, COBERTURA_FILE_NAME); | ||
| job.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [cobertura('**/*.xml'),jacocoAdapter('**/*.xml')]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes no sense, each adapter should read only files that it can understand.
| private static final String JACOCO_FILE_NAME = "jacoco-analysis-model.xml"; | ||
| private static final String JACOCO_LESS_FILE_NAME = "jacoco-codingstyle.xml"; | ||
| private static final String COBERTURA_FILE_NAME = "cobertura.xml"; | ||
| private static final String COBERTURA_FILE_NAME_2 = "cobertura2.xml"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use meaningful names
src/test/java/io/jenkins/plugins/coverage/model/CoveragePluginITest.java Show resolved Hide resolved
| WorkflowJob job2 = createPipelineWithWorkspaceFiles(JACOCO_LESS_FILE_NAME); | ||
| job2.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [jacocoAdapter('**/*.xml')]," | ||
| //+ "sourceFileResolver: sourceFiles('STORE_LAST_BUILD')," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See chat on how to specify the reference build
| CoverageBuildAction coverageResult = build.getAction(CoverageBuildAction.class); | ||
| assertThat(coverageResult.getLineCoverage()).isEqualTo(new Coverage(6083, 6368-6083)); | ||
| | ||
| //TODO: Wie assertet man publish checks??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check for the existence/absence of the string:
[Checks API] No suitable checks publisher found.
uhafner left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are in a somehow unfinished state.
| <dependency> | ||
| <groupId>io.jenkins.plugins</groupId> | ||
| <artifactId>warnings-ng</artifactId> | ||
| <version>9.6.0-SNAPSHOT</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci</groupId> | ||
| <artifactId>acceptance-test-harness</artifactId> | ||
| <version>1.101</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci</groupId> | ||
| <artifactId>acceptance-test-harness</artifactId> | ||
| <version>1.103</version> | ||
| <scope>test</scope> | ||
| </dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These make no sense.
| /** | ||
| * Integration test for the coverage API plugin. | ||
| * | ||
| * todo: DRY, constants for values, javadoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| //HealthReportingAction result = build.getAction(HealthReportingAction.class); | ||
| //assertThat(result.getBuildHealth()).isEqualTo(null); //healthReport is null why??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work now?
| @Test | ||
| public void coveragePluginPipelineFailUnhealthyWithResultSuccess() { | ||
| WorkflowJob job = createPipelineWithWorkspaceFiles(JACOCO_FILE_WITH_HIGHER_COVERAGE); | ||
| job.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [jacocoAdapter('**/*.xml')]," | ||
| + "globalThresholds: [[failUnhealthy: true, thresholdTarget: 'Line', unhealthyThreshold: 90.0]]" | ||
| + "}", true)); | ||
| | ||
| Run<?, ?> build = buildWithResult(job, Result.SUCCESS); | ||
| assertThat(build.getNumber()).isEqualTo(1); | ||
| } | ||
| | ||
| | ||
| @Test | ||
| public void coveragePluginPipelineFailUnstable() { | ||
| WorkflowJob job = createPipelineWithWorkspaceFiles(JACOCO_FILE_WITH_HIGHER_COVERAGE); | ||
| job.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [jacocoAdapter('**/*.xml')]," | ||
| + "failUnstable: true," | ||
| + "globalThresholds: [[thresholdTarget: 'Line', unstableThreshold: 96.0]]" | ||
| + "}", true)); | ||
| | ||
| Run<?, ?> build = buildWithResult(job, Result.FAILURE); | ||
| assertThat(build.getNumber()).isEqualTo(1); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is hard to understand why it fails in one method only. Maybe adding a comment or improving the method names would help (or using some constants).
| copyFilesToWorkspace(job, JACOCO_FILE_WITH_HIGHER_COVERAGE); | ||
| job.setDefinition(new CpsFlowDefinition("node {" | ||
| + "publishCoverage adapters: [jacocoAdapter('" + JACOCO_FILE_WITH_HIGHER_COVERAGE + "')]\n" | ||
| + "discoverReferenceBuild(referenceJob: '" + job.getName() + "')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be called before recording.
| /** | ||
| * Test ignored ... falsche Imports? | ||
| * java.lang.IllegalArgumentException: Unknown server host key algorithm 'ssh-ed25519' | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code and pom actually is broken.
| I'm closing this PR as we can only merge one of the 4 integration test PRs. There is no need to add additional commits. |
Added Integration test class and 2 cobertura-files for the Integration-test, because there where problems with the existing ones.
Created PR for the lesson on Thursday 02.12.