Skip to content

Commit

Permalink
issue/5: TestImpactAnalysis#parseCsvFile should consider all types of…
Browse files Browse the repository at this point in the history
… coverage to determine covered classes
  • Loading branch information
fmck3516 committed Nov 27, 2023
1 parent 3a5401d commit 6fc844d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
36 changes: 25 additions & 11 deletions skippy-core/src/main/java/io/skippy/core/TestImpactAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static java.lang.Integer.parseInt;
import static java.util.Arrays.asList;
Expand All @@ -42,6 +39,10 @@ class TestImpactAnalysis {

static final TestImpactAnalysis UNAVAILABLE = new TestImpactAnalysis(emptyMap());

private enum JACOCO_CSV_COLUMN {
GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED
}

private final Map<FullyQualifiedClassName, List<FullyQualifiedClassName>> testCoverage;

/**
Expand Down Expand Up @@ -89,7 +90,7 @@ private static List<FullyQualifiedClassName> parseCsvFile(Path csvFile) {
content.remove(0);
var coveredClasses = new ArrayList<FullyQualifiedClassName>();
for (var line : content) {
coveredClasses.addAll(parseCsvFile(line));
coveredClasses.addAll(parseCsvLine(line));
}
return coveredClasses;
} catch (Exception e) {
Expand All @@ -98,12 +99,24 @@ private static List<FullyQualifiedClassName> parseCsvFile(Path csvFile) {
}
}

private static List<FullyQualifiedClassName> parseCsvFile(String line) {
private static List<FullyQualifiedClassName> parseCsvLine(String line) {
var csvColumns = line.split(",");
var methodsCoveredCount = parseInt(csvColumns[12]);
var pkg = csvColumns[1];
var clazz = csvColumns[2];
if (methodsCoveredCount > 0) {
var pkg = csvColumns[JACOCO_CSV_COLUMN.PACKAGE.ordinal()];
var clazz = csvColumns[JACOCO_CSV_COLUMN.CLASS.ordinal()];

boolean coverageDetected = false;
for (var column : asList(
JACOCO_CSV_COLUMN.INSTRUCTION_COVERED,
JACOCO_CSV_COLUMN.BRANCH_COVERED,
JACOCO_CSV_COLUMN.LINE_COVERED,
JACOCO_CSV_COLUMN.COMPLEXITY_COVERED,
JACOCO_CSV_COLUMN.METHOD_COVERED)) {
if (parseInt(csvColumns[column.ordinal()]) > 0) {
coverageDetected = true;
}
}

if (coverageDetected) {
return asList(new FullyQualifiedClassName(pkg + "." + clazz));
}
return emptyList();
Expand All @@ -120,4 +133,5 @@ private static String toClassName(Path csvFile) {
// com_example_Foo -> com.example.Foo
return withoutExtension.replaceAll("_", ".");
}
}

}
1 change: 1 addition & 0 deletions skippy-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
test {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
useJUnitPlatform()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

/**
* Functional test for the Getting Started With Gradle & JUnit 5 Tutorial.
* Smoke test for the Skippy plugin.
*
* @author Florian McKee
*/
public class SkippyPluginSmokeTest {

@Test
public void runTestsWithoutAnalysis() throws Exception {
public void smokeTestSkippyPlugin() throws Exception {

var buildFile = new File(getClass().getResource("skippyplugin/build.gradle").toURI());
var projectDir = buildFile.getParentFile();
Expand Down

0 comments on commit 6fc844d

Please sign in to comment.