Search in sources :

Example 1 with TestCaseJSON

use of fr.inria.diversify.dspot.selector.json.coverage.TestCaseJSON in project dspot by STAMP-project.

the class JacocoCoverageSelector method jsonReport.

private void jsonReport(CoverageResults coverageResults) {
    TestClassJSON testClassJSON;
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    final File file = new File(this.configuration.getOutputDirectory() + "/" + this.currentClassTestToBeAmplified.getQualifiedName() + "_jacoco_instr_coverage.json");
    if (file.exists()) {
        try {
            testClassJSON = gson.fromJson(new FileReader(file), TestClassJSON.class);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    } else {
        testClassJSON = new TestClassJSON(this.currentClassTestToBeAmplified.getQualifiedName(), this.currentClassTestToBeAmplified.getMethods().size(), this.initialCoverage.instructionsCovered, this.initialCoverage.instructionsTotal, coverageResults.instructionsCovered, coverageResults.instructionsTotal);
    }
    this.selectedAmplifiedTest.forEach(ctMethod -> new TestCaseJSON(ctMethod.getSimpleName(), Counter.getInputOfSinceOrigin(ctMethod), Counter.getAssertionOfSinceOrigin(ctMethod), this.selectedToBeAmplifiedCoverageResultsMap.get(ctMethod.getSimpleName()).instructionsCovered, this.selectedToBeAmplifiedCoverageResultsMap.get(ctMethod.getSimpleName()).instructionsTotal));
    try (FileWriter writer = new FileWriter(file, false)) {
        writer.write(gson.toJson(testClassJSON));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) TestCaseJSON(fr.inria.diversify.dspot.selector.json.coverage.TestCaseJSON) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) TestClassJSON(fr.inria.diversify.dspot.selector.json.coverage.TestClassJSON)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TestCaseJSON (fr.inria.diversify.dspot.selector.json.coverage.TestCaseJSON)1 TestClassJSON (fr.inria.diversify.dspot.selector.json.coverage.TestClassJSON)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1