-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CoveredTestResultPerTestMethod API (#95)
* Partially implement CoveredTestResultPerTestMethod API Signed-off-by: André Silva <[email protected]> * Add assertions for coverage map Signed-off-by: André Silva <[email protected]> * Rename new runner classes Signed-off-by: André Silva <[email protected]> * Fix runner class names in EntryPoint Signed-off-by: André Silva <[email protected]> * Add JUnit4JacocoRunnerCoveredResultPerTestMethodTest Signed-off-by: André Silva <[email protected]> * Fix CoverageFromClass not being serializable. Because CoverageFromClass was not serializable, loading a serialized CoverageDetailed object was not possible. Signed-off-by: André Silva <[email protected]> * Update tests. Signed-off-by: André Silva <[email protected]> * Add documentation Signed-off-by: André Silva <[email protected]> * Fix flakyness Signed-off-by: André Silva <[email protected]> * Add API documentation in the README Signed-off-by: André Silva <[email protected]>
- Loading branch information
1 parent
3541dd9
commit d7dd726
Showing
32 changed files
with
1,389 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/eu/stamp_project/testrunner/listener/CoveredTestResultPerTestMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package eu.stamp_project.testrunner.listener; | ||
|
||
import eu.stamp_project.testrunner.utils.ConstantsHelper; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
/** | ||
* Stores both the individual test unit (i.e. method) results as well as the individual coverage | ||
* information for each of them. | ||
* | ||
* @author andre15silva | ||
*/ | ||
public interface CoveredTestResultPerTestMethod extends TestResult, Serializable { | ||
|
||
public static final String SERIALIZE_NAME = "CoveredTestResultPerTest"; | ||
|
||
public static final String OUTPUT_DIR = "target" + ConstantsHelper.FILE_SEPARATOR; | ||
|
||
public static final String EXTENSION = ".ser"; | ||
|
||
public Map<String, Coverage> getCoverageResultsMap(); | ||
|
||
public Coverage getCoverageOf(String testMethodName); | ||
|
||
public void save(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
...in/java/eu/stamp_project/testrunner/listener/impl/CoveredTestResultPerTestMethodImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
package eu.stamp_project.testrunner.listener.impl; | ||
|
||
import eu.stamp_project.testrunner.listener.Coverage; | ||
import eu.stamp_project.testrunner.listener.CoverageTransformer; | ||
import eu.stamp_project.testrunner.listener.CoveredTestResultPerTestMethod; | ||
import eu.stamp_project.testrunner.listener.TestResult; | ||
import eu.stamp_project.testrunner.runner.Failure; | ||
import eu.stamp_project.testrunner.runner.Loader; | ||
import eu.stamp_project.testrunner.utils.ConstantsHelper; | ||
import org.jacoco.core.data.ExecutionDataStore; | ||
import org.jacoco.core.data.SessionInfoStore; | ||
import org.jacoco.core.runtime.RuntimeData; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Default implementation of the CoveredTestResultPerTestMethod interface | ||
* | ||
* @author andre15silva | ||
*/ | ||
public class CoveredTestResultPerTestMethodImpl implements CoveredTestResultPerTestMethod { | ||
|
||
private static final long serialVersionUID = -789740001022671146L; | ||
|
||
protected final Map<String, Coverage> coverageResultsMap; | ||
|
||
protected final String classesDirectory; | ||
|
||
protected transient RuntimeData data; | ||
|
||
protected transient ExecutionDataStore executionData; | ||
|
||
protected transient SessionInfoStore sessionInfos; | ||
|
||
protected transient CoverageTransformer coverageTransformer; | ||
|
||
private List<String> runningTests; | ||
private List<Failure> failingTests; | ||
private List<Failure> assumptionFailingTests; | ||
private List<String> ignoredTests; | ||
|
||
public CoveredTestResultPerTestMethodImpl(RuntimeData data, String classesDirectory, CoverageTransformer coverageTransformer) { | ||
this.data = data; | ||
this.classesDirectory = classesDirectory; | ||
this.coverageResultsMap = new HashMap<>(); | ||
this.coverageTransformer = coverageTransformer; | ||
this.runningTests = new ArrayList<>(); | ||
this.failingTests = new ArrayList<>(); | ||
this.assumptionFailingTests = new ArrayList<>(); | ||
this.ignoredTests = new ArrayList<>(); | ||
|
||
} | ||
|
||
public String getClassesDirectory() { | ||
return classesDirectory; | ||
} | ||
|
||
public RuntimeData getData() { | ||
return data; | ||
} | ||
|
||
public ExecutionDataStore getExecutionData() { | ||
return executionData; | ||
} | ||
|
||
public SessionInfoStore getSessionInfos() { | ||
return sessionInfos; | ||
} | ||
|
||
public CoverageTransformer getCoverageTransformer() { | ||
return coverageTransformer; | ||
} | ||
|
||
public void setData(RuntimeData data) { | ||
this.data = data; | ||
} | ||
|
||
public void setExecutionData(ExecutionDataStore executionData) { | ||
this.executionData = executionData; | ||
} | ||
|
||
public void setSessionInfos(SessionInfoStore sessionInfos) { | ||
this.sessionInfos = sessionInfos; | ||
} | ||
|
||
@Override | ||
public Map<String, Coverage> getCoverageResultsMap() { | ||
return coverageResultsMap; | ||
} | ||
|
||
@Override | ||
public Coverage getCoverageOf(String testMethodName) { | ||
return this.getCoverageResultsMap().get(testMethodName); | ||
} | ||
|
||
@Override | ||
public List<String> getRunningTests() { | ||
return runningTests; | ||
} | ||
|
||
@Override | ||
public List<String> getPassingTests() { | ||
final List<String> failing = this.failingTests.stream() | ||
.map(failure -> failure.testCaseName) | ||
.collect(Collectors.toList()); | ||
final List<String> assumptionFailing = this.assumptionFailingTests.stream() | ||
.map(failure -> failure.testCaseName) | ||
.collect(Collectors.toList()); | ||
return this.runningTests.stream() | ||
.filter(description -> !assumptionFailing.contains(description)) | ||
.filter(description -> !failing.contains(description)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public TestResult aggregate(TestResult that) { | ||
if (that instanceof CoveredTestResultPerTestMethodImpl) { | ||
final CoveredTestResultPerTestMethodImpl thatListener = (CoveredTestResultPerTestMethodImpl) that; | ||
this.runningTests.addAll(thatListener.runningTests); | ||
this.failingTests.addAll(thatListener.failingTests); | ||
this.assumptionFailingTests.addAll(thatListener.assumptionFailingTests); | ||
this.ignoredTests.addAll(thatListener.ignoredTests); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<Failure> getFailingTests() { | ||
return failingTests; | ||
} | ||
|
||
@Override | ||
public List<Failure> getAssumptionFailingTests() { | ||
return assumptionFailingTests; | ||
} | ||
|
||
@Override | ||
public List<String> getIgnoredTests() { | ||
return ignoredTests; | ||
} | ||
|
||
@Override | ||
public Failure getFailureOf(String testMethodName) { | ||
return this.getFailingTests().stream() | ||
.filter(failure -> failure.testCaseName.equals(testMethodName)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException(String.format("Could not find %s in failing test", testMethodName))); | ||
} | ||
|
||
@Override | ||
public void save() { | ||
File outputDir = new File(TestResult.OUTPUT_DIR); | ||
if (!outputDir.exists()) { | ||
if (!outputDir.mkdirs()) { | ||
System.err.println("Error while creating output dir"); | ||
} | ||
} | ||
File f = new File(outputDir, SERIALIZE_NAME + EXTENSION); | ||
try (FileOutputStream fout = new FileOutputStream(f)) { | ||
try (ObjectOutputStream oos = new ObjectOutputStream(fout)) { | ||
oos.writeObject(this); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} catch (Exception e) { | ||
System.err.println("Error while writing serialized file."); | ||
throw new RuntimeException(e); | ||
} | ||
System.out.println("File saved to the following path: " + f.getAbsolutePath()); | ||
} | ||
|
||
/** | ||
* Load from serialized object | ||
* | ||
* @return an Instance of CoveragePerTestMethod loaded from a serialized file. | ||
*/ | ||
public static CoveredTestResultPerTestMethodImpl load() { | ||
return new Loader<CoveredTestResultPerTestMethodImpl>().load(SERIALIZE_NAME); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CoveredTestResultPerTestMethodImpl{" + | ||
"coverageResultsMap=" + this.coverageResultsMap.keySet() | ||
.stream() | ||
.map(test -> "\t" + test + ": " + coverageResultsMap.get(test).toString()) | ||
.collect(Collectors.joining(ConstantsHelper.LINE_SEPARATOR)) + | ||
", classesDirectory='" + classesDirectory + '\'' + | ||
", data=" + data + | ||
", executionData=" + executionData + | ||
", sessionInfos=" + sessionInfos + | ||
", coverageTransformer=" + coverageTransformer + | ||
", runningTests=" + runningTests + | ||
", failingTests=" + failingTests + | ||
", assumptionFailingTests=" + assumptionFailingTests + | ||
", ignoredTests=" + ignoredTests + | ||
'}'; | ||
} | ||
|
||
} |
Oops, something went wrong.