Search in sources :

Example 1 with TestCaseJSON

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

the class ExecutedMutantSelector method reportJSONMutants.

private void reportJSONMutants() {
    if (this.currentClassTestToBeAmplified == null) {
        return;
    }
    TestClassJSON testClassJSON;
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    final File file = new File(this.configuration.getOutputDirectory() + "/" + this.currentClassTestToBeAmplified.getQualifiedName() + "_mutants_executed.json");
    if (file.exists()) {
        try {
            testClassJSON = gson.fromJson(new FileReader(file), TestClassJSON.class);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    } else {
        testClassJSON = new TestClassJSON(getNbMutantExecutedOriginally(this.currentClassTestToBeAmplified.getQualifiedName()), this.currentClassTestToBeAmplified.getQualifiedName(), this.currentClassTestToBeAmplified.getMethods().stream().filter(AmplificationChecker::isTest).count());
    }
    List<CtMethod> keys = new ArrayList<>(this.mutantExecutedPerAmplifiedTestMethod.keySet());
    keys.forEach(amplifiedTest -> {
        List<PitResult> pitResults = new ArrayList<>(this.mutantExecutedPerAmplifiedTestMethod.get(amplifiedTest));
        final List<MutantJSON> mutantsJson = new ArrayList<>();
        pitResults.forEach(pitResult -> mutantsJson.add(new MutantJSON(pitResult.getFullQualifiedNameMutantOperator(), pitResult.getLineNumber(), pitResult.getNameOfMutatedMethod())));
        if (amplifiedTest == null) {
            testClassJSON.addTestCase(new TestCaseJSON(this.currentClassTestToBeAmplified.getSimpleName(), Counter.getAllAssertions(), Counter.getAllInput(), mutantsJson));
        } else {
            testClassJSON.addTestCase(new TestCaseJSON(amplifiedTest.getSimpleName(), Counter.getAssertionOfSinceOrigin(amplifiedTest), Counter.getInputOfSinceOrigin(amplifiedTest), mutantsJson));
        }
    });
    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) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) TestCaseJSON(fr.inria.diversify.dspot.selector.json.mutant.TestCaseJSON) FileReader(java.io.FileReader) PitResult(fr.inria.diversify.mutant.pit.PitResult) File(java.io.File) CtMethod(spoon.reflect.declaration.CtMethod) MutantJSON(fr.inria.diversify.dspot.selector.json.mutant.MutantJSON) TestClassJSON(fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON)

Example 2 with TestCaseJSON

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

the class PitMutantScoreSelector method reportJSONMutants.

private void reportJSONMutants() {
    if (this.currentClassTestToBeAmplified == null) {
        return;
    }
    TestClassJSON testClassJSON;
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    final File file = new File(this.configuration.getOutputDirectory() + "/" + this.currentClassTestToBeAmplified.getQualifiedName() + "_mutants_killed.json");
    if (file.exists()) {
        try {
            testClassJSON = gson.fromJson(new FileReader(file), TestClassJSON.class);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    } else {
        testClassJSON = new TestClassJSON(getNbMutantKilledOriginally(this.currentClassTestToBeAmplified.getQualifiedName()), this.currentClassTestToBeAmplified.getQualifiedName(), this.currentClassTestToBeAmplified.getMethods().stream().filter(AmplificationChecker::isTest).count());
    }
    List<CtMethod> keys = new ArrayList<>(this.testThatKilledMutants.keySet());
    keys.forEach(amplifiedTest -> {
        List<PitResult> pitResults = new ArrayList<>(this.testThatKilledMutants.get(amplifiedTest));
        final List<MutantJSON> mutantsJson = new ArrayList<>();
        pitResults.forEach(pitResult -> mutantsJson.add(new MutantJSON(pitResult.getFullQualifiedNameMutantOperator(), pitResult.getLineNumber(), pitResult.getNameOfMutatedMethod())));
        if (amplifiedTest == null) {
            testClassJSON.addTestCase(new TestCaseJSON(this.currentClassTestToBeAmplified.getSimpleName(), Counter.getAllAssertions(), Counter.getAllInput(), mutantsJson));
        } else {
            testClassJSON.addTestCase(new TestCaseJSON(amplifiedTest.getSimpleName(), Counter.getAssertionOfSinceOrigin(amplifiedTest), Counter.getInputOfSinceOrigin(amplifiedTest), mutantsJson));
        }
    });
    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) Gson(com.google.gson.Gson) TestCaseJSON(fr.inria.diversify.dspot.selector.json.mutant.TestCaseJSON) PitResult(fr.inria.diversify.mutant.pit.PitResult) CtMethod(spoon.reflect.declaration.CtMethod) MutantJSON(fr.inria.diversify.dspot.selector.json.mutant.MutantJSON) TestClassJSON(fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 MutantJSON (fr.inria.diversify.dspot.selector.json.mutant.MutantJSON)2 TestCaseJSON (fr.inria.diversify.dspot.selector.json.mutant.TestCaseJSON)2 TestClassJSON (fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON)2 PitResult (fr.inria.diversify.mutant.pit.PitResult)2 CtMethod (spoon.reflect.declaration.CtMethod)2 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 ArrayList (java.util.ArrayList)1