Skip to content

Commit

Permalink
Merge pull request #135 from cqse/cr/22849_duplicate_test_entries
Browse files Browse the repository at this point in the history
CR#22849 Fixed duplicate tests
  • Loading branch information
AnonymFx authored May 7, 2020
2 parents b112b53 + 80b1203 commit b97cdba
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 4 deletions.
1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ We use [semantic versioning](http://semver.org/):
- [feature] Use git.commit.id from git.properties instead of branch and timestamp
- [breaking change] Reduce XML report size by only including source file coverage, no class coverage
- [feature] New option `--ignore-uncovered-classes` to further reduce size of XML reports
- [fix] converter produces duplicate test entries for testwise coverage

# 15.5.0
- [feature] add TIA client library for integrating TIA in your custom test framework
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -33,4 +36,39 @@ public void testSmokeTest(@TempDir File tempDir) throws Exception {
assertThat(xml).isNotEmpty().contains("<package").contains("<sourcefile").contains("<counter").contains("TestClass");
}

/**
* Ensures that running the converter on valid input does not yield any errors and produces a coverage XML report.
*/
@Test
public void testTestwiseCoverageSmokeTest(@TempDir File tempDir) throws Exception {
File inputDir = new File(tempDir, "input");
inputDir.mkdir();
copyResourceTo("coverage-testwise.exec", inputDir);
copyResourceTo("test-list.json", inputDir);
copyResourceTo("test-execution.json", inputDir);
File classFile = new File(getClass().getResource("classes.zip").toURI());
File outputFile = new File(tempDir, "testwise-coverage.json");

ConvertCommand arguments = new ConvertCommand();
arguments.inputFiles = Collections.singletonList(inputDir.getAbsolutePath());
arguments.outputFile = outputFile.getAbsolutePath();
arguments.classDirectoriesOrZips = Collections.singletonList(classFile.getAbsolutePath());

new Converter(arguments).runTestwiseCoverageReportGeneration();

String json = FileSystemUtils.readFileUTF8(new File(tempDir, "testwise-coverage-1.json"));
assertThat(json).
contains(
"\"uniformPath\": \"[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testFunctions(org.conqat.lib.cqddl.CQDDLTest)]\"")
.contains(
"\"uniformPath\": \"[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testDirectObjectInsertion(org.conqat.lib.cqddl.CQDDLTest)]\"")
.contains("\"uniformPath\": \"[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testKeyAbbreviations(org.conqat.lib.cqddl.CQDDLTest)]\"")
.contains("\"uniformPath\": \"[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testKeyAbbreviations(org.conqat.lib.cqddl.CQDDLTest)]\"")
.contains("\"result\": \"PASSED\"").contains("\"duration\": 1234").contains("\"coveredLines\": \"33,46-47");
}

private void copyResourceTo(String name, File targetDir) throws URISyntaxException, IOException {
File execFile = new File(getClass().getResource(name).toURI());
Files.copy(execFile.toPath(), new File(targetDir, name).toPath());
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"uniformPath": "[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testDirectObjectInsertion(org.conqat.lib.cqddl.CQDDLTest)]"
},
{
"uniformPath": "[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testFunctions(org.conqat.lib.cqddl.CQDDLTest)]",
"duration": 1234,
"result": "PASSED"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"uniformPath": "[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testDirectObjectInsertion(org.conqat.lib.cqddl.CQDDLTest)]"
},
{
"uniformPath": "[engine:junit-vintage]/[runner:org.conqat.lib.cqddl.CQDDLTest]/[test:testFunctions(org.conqat.lib.cqddl.CQDDLTest)]"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TestInfoFactory {
private Map<String, TestExecution> testExecutionsMap = new HashMap<>();

/** Holds all uniform paths for tests that have been written to the outputFile. */
private final Set<String> uniformPathsWithCoverage = new HashSet<>();
private final Set<String> processedTestUniformPaths = new HashSet<>();

public TestInfoFactory(List<TestDetails> testDetails, List<TestExecution> testExecutions) {
for (TestDetails testDetail : testDetails) {
Expand All @@ -44,7 +44,7 @@ public TestInfoFactory(List<TestDetails> testDetails, List<TestExecution> testEx
*/
public TestInfo createFor(TestCoverageBuilder testCoverageBuilder) {
String resolvedUniformPath = resolveUniformPath(testCoverageBuilder.getUniformPath());
uniformPathsWithCoverage.add(resolvedUniformPath);
processedTestUniformPaths.add(resolvedUniformPath);

TestInfoBuilder container = new TestInfoBuilder(resolvedUniformPath);
container.setCoverage(testCoverageBuilder);
Expand All @@ -65,11 +65,20 @@ public TestInfo createFor(TestCoverageBuilder testCoverageBuilder) {
public List<TestInfo> createTestInfosWithoutCoverage() {
ArrayList<TestInfo> results = new ArrayList<>();
for (TestDetails testDetails : testDetailsMap.values()) {
if (uniformPathsWithCoverage.contains(testDetails.uniformPath)) {
if (!processedTestUniformPaths.contains(testDetails.uniformPath)) {
TestInfoBuilder testInfo = new TestInfoBuilder(testDetails.uniformPath);
testInfo.setDetails(testDetails);
testInfo.setExecution(testExecutionsMap.get(testDetails.uniformPath));
results.add(testInfo.build());
processedTestUniformPaths.add(testDetails.uniformPath);
}
}
for (TestExecution testExecution : testExecutionsMap.values()) {
if (!processedTestUniformPaths.contains(testExecution.getUniformPath())) {
System.err.println("Test " + testExecution.getUniformPath() + " was executed but no coverage was found. " +
"Please make sure that you did provide all relevant exec files and that the test IDs passed to " +
"the agent match the ones from the provided test execution list.");
processedTestUniformPaths.add(testExecution.getUniformPath());
}
}
return results;
Expand Down

0 comments on commit b97cdba

Please sign in to comment.