Skip to content

Commit 5128be6

Browse files
authored
Merge pull request #300 from Checkmarx/other/benalvo/add-coverage-report
Optimize tests runtime and add coverage report for integration tests (AST-79390)
2 parents 896b74f + a9d648e commit 5128be6

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: Checkmarx One Jetbrains Plugin CI
2-
32
on: [ pull_request, workflow_dispatch ]
4-
53
env:
64
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
75
CX_APIKEY: ${{ secrets.CX_APIKEY }}
@@ -14,12 +12,9 @@ env:
1412
CX_NOT_MATCH_TEST_PROJECT: ${{ secrets.CX_NOT_MATCH_TEST_PROJECT }}
1513
CX_NOT_MATCH_TEST_BRANCH: ${{ secrets.CX_NOT_MATCH_TEST_BRANCH }}
1614
CX_NOT_MATCH_TEST_SCAN_ID: ${{ secrets.CX_NOT_MATCH_TEST_SCAN_ID }}
17-
18-
1915
concurrency:
2016
group: ${{ github.head_ref || github.run_id }}
2117
cancel-in-progress: true
22-
2318
jobs:
2419
testUI:
2520
needs: [ testIntegration ]
@@ -35,7 +30,7 @@ jobs:
3530
distribution: zulu
3631
java-version: 11
3732
- name: Setup FFmpeg
38-
uses: FedericoCarboni/setup-ffmpeg@v2
33+
uses: FedericoCarboni/setup-ffmpeg@583042d32dd1cabb8bd09df03bde06080da5c87c #v2.0.0
3934
with:
4035
# Not strictly necessary, but it may prevent rate limit
4136
# errors especially on GitHub-hosted macos machines.
@@ -94,13 +89,21 @@ jobs:
9489
- name: Clean
9590
run: ./gradlew clean
9691
# Run tests
97-
- name: Tests
98-
run: ./gradlew test -i --tests com.checkmarx.intellij.standard*
92+
- name: Run Tests with coverage report
93+
id: test_results
94+
run: |
95+
./gradlew test --tests "com.checkmarx.intellij.standard*" jacocoTestReport
96+
# Save coverage report as an artifact
97+
- name: Upload Coverage Report
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: coverage-report
101+
path: build/reports/jacoco/test/html/
99102
# Save report if tests fail
100103
- name: Save fails report
101104
if: ${{ failure() }}
102105
uses: actions/upload-artifact@v4
103106
with:
104107
name: test-fails-report-integration
105108
path: |
106-
build/reports
109+
build/reports

build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'io.freefair.lombok' version '8.6'
33
id 'org.jetbrains.intellij' version '1.17.4'
44
id 'java'
5+
id 'jacoco'
56
}
67

78
group 'com.checkmarx'
@@ -20,6 +21,18 @@ repositories {
2021
}
2122
}
2223

24+
jacoco {
25+
toolVersion = "0.8.7"
26+
}
27+
28+
tasks.jacocoTestReport {
29+
dependsOn test // Ensure tests run before generating the report
30+
reports {
31+
xml.required.set(true)
32+
html.required.set(true)
33+
}
34+
}
35+
2336
dependencies {
2437
testImplementation 'com.intellij.remoterobot:remote-robot:' + remoteRobotVersion
2538
testImplementation('com.intellij.remoterobot:remote-fixtures:' + remoteRobotVersion) {
@@ -85,6 +98,15 @@ runIdeForUiTests {
8598
systemProperty 'jb.consents.confirmation.enabled', 'false'
8699
}
87100

101+
jacocoTestReport {
102+
additionalSourceDirs.setFrom(files(sourceSets.main.allSource.srcDirs))
103+
classDirectories.setFrom(
104+
fileTree(dir: "$buildDir/classes/java/main", excludes: [])
105+
)
106+
executionData.setFrom(fileTree(dir: "$buildDir", includes: ["jacoco/test.exec"]))
107+
}
108+
109+
88110
publishPlugin {
89111
token.set System.getenv("PUBLISH_TOKEN")
90112
if (project.hasProperty("rchannels")) {

src/test/java/com/checkmarx/intellij/standard/commands/TestScan.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ public void testGetList() {
2727
String msg = String.format("project: %s branch: %s scans: %d", project.getId(), Environment.BRANCH_NAME, scans.size());
2828
Assertions.assertTrue(scans.size() > 0, msg);
2929
Assertions.assertTrue(scans.size() <= 10000, msg);
30-
for (com.checkmarx.ast.scan.Scan scan : scans) {
31-
Assertions.assertEquals("Completed", scan.getStatus());
32-
Assertions.assertEquals(Environment.BRANCH_NAME, scan.getBranch());
33-
Assertions.assertEquals(getEnvProject().getId(), scan.getProjectId());
34-
}
30+
31+
// Check that all scans are for the correct project and branch and have completed
32+
Assertions.assertTrue(scans.stream().allMatch(scan -> scan.getProjectId().equals(project.getId()) && scan.getBranch().equals(Environment.BRANCH_NAME) && scan.getStatus().equals("Completed")));
3533
}
3634

3735
@Test

src/test/java/com/checkmarx/intellij/standard/commands/TestScanAsca.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.intellij.psi.PsiFile;
1414
import com.intellij.psi.PsiManager;
1515
import org.junit.jupiter.api.Assertions;
16+
import org.junit.jupiter.api.Test;
1617

1718
public class TestScanAsca extends BaseTest {
1819
AscaService ascaService = new AscaService();
@@ -43,6 +44,7 @@ private PsiFile createPsiFileFromPath(String filePath) {
4344
return psiFile;
4445
}
4546

47+
@Test
4648
public void testRunAscaScan_FileWithVulnerabilities_Success() {
4749
PsiFile psiFile = createPsiFileFromPath("src/test/java/com/checkmarx/intellij/standard/data/python-vul-file.py");
4850
Project project = ProjectManager.getInstance().getDefaultProject();
@@ -55,6 +57,7 @@ public void testRunAscaScan_FileWithVulnerabilities_Success() {
5557
});
5658
}
5759

60+
@Test
5861
public void testRunAscaScan_FileWithNoVulnerabilities_Success() {
5962
PsiFile psiFile = createPsiFileFromPath("src/test/java/com/checkmarx/intellij/standard/data/csharp-no-vul.cs");
6063
Project project = ProjectManager.getInstance().getDefaultProject();
@@ -66,6 +69,7 @@ public void testRunAscaScan_FileWithNoVulnerabilities_Success() {
6669
});
6770
}
6871

72+
@Test
6973
public void testRunAscaScan_FileWithoutExtension_Fail() {
7074
PsiFile psiFile = createPsiFileFromPath("src/test/java/com/checkmarx/intellij/standard/data/file");
7175
Project project = ProjectManager.getInstance().getDefaultProject();

0 commit comments

Comments
 (0)