Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Conversation

@twilleit
Copy link

@twilleit twilleit commented Dec 1, 2021

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.


WorkflowJob job2 = createPipelineWithWorkspaceFiles(JACOCO_LESS_FILE_NAME);
job2.setDefinition(new CpsFlowDefinition("node {"
+ "publishCoverage adapters: [jacocoAdapter('**/*.xml')],"
Copy link
Member

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') 
Copy link
Member

@uhafner uhafner left a 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();
Copy link
Member

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.

Comment on lines 72 to 76
WorkflowJob job = createPipelineWithWorkspaceFiles(JACOCO_FILE_NAME, JACOCO_LESS_FILE_NAME);
job.setDefinition(new CpsFlowDefinition("node {"
+ "publishCoverage adapters: [jacocoAdapter('**/*.xml')]"
+ "}", true));

Copy link
Member

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));
Copy link
Member

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.

Comment on lines +77 to +78
Run<?, ?> build = buildSuccessfully(job);
assertThat(build.getNumber()).isEqualTo(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY

Comment on lines +120 to +125
job.setDefinition(new CpsFlowDefinition("node {"
+ "publishCoverage adapters: [cobertura('**/*.xml')]"
+ "}", true));

Run<?, ?> build = buildSuccessfully(job);
assertThat(build.getNumber()).isEqualTo(1);
Copy link
Member

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')]"
Copy link
Member

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use meaningful names

WorkflowJob job2 = createPipelineWithWorkspaceFiles(JACOCO_LESS_FILE_NAME);
job2.setDefinition(new CpsFlowDefinition("node {"
+ "publishCoverage adapters: [jacocoAdapter('**/*.xml')],"
//+ "sourceFileResolver: sourceFiles('STORE_LAST_BUILD'),"
Copy link
Member

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???
Copy link
Member

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. 
Copy link
Member

@uhafner uhafner left a 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.

Comment on lines +198 to +215
<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>
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment on lines +192 to +193
//HealthReportingAction result = build.getAction(HealthReportingAction.class);
//assertThat(result.getBuildHealth()).isEqualTo(null); //healthReport is null why???
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work now?

Comment on lines +210 to +234
@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);
}
Copy link
Member

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() + "')"
Copy link
Member

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.

Comment on lines +349 to +352
/**
* Test ignored ... falsche Imports?
* java.lang.IllegalArgumentException: Unknown server host key algorithm 'ssh-ed25519'
*/
Copy link
Member

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.

@uhafner
Copy link
Member

uhafner commented Jan 20, 2022

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.

@uhafner uhafner closed this Jan 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants