Search in sources :

Example 1 with TestDataMutator

use of fr.inria.diversify.dspot.amplifier.TestDataMutator in project dspot by STAMP-project.

the class ExecutedMutantSelectorTest method test.

@Ignore
@Test
public void test() throws Exception {
    // pre computing the number of executed mutants...
    Main.verbose = true;
    AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).runPit(Utils.getInputProgram().getProgramDir());
    final List<PitResult> pitResults = PitResultParser.parseAndDelete(Utils.getInputProgram().getProgramDir() + "target/pit-reports/");
    final ExecutedMutantSelector testSelector = new ExecutedMutantSelector();
    DSpot dspot = new DSpot(Utils.getInputConfiguration(), 1, Collections.singletonList(new TestDataMutator()), testSelector);
    final CtType amplifyTest = dspot.amplifyTest(Utils.findClass("example.TestSuiteExample"), Collections.singletonList(Utils.findMethod("example.TestSuiteExample", "test8")));
    // pretty print it
    DSpotUtils.printCtTypeToGivenDirectory(amplifyTest, new File(DSpotCompiler.pathToTmpTestSources));
    // then compile
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).buildClasspath(Utils.getInputProgram().getProgramDir()) + AmplificationHelper.PATH_SEPARATOR + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getClassesDir() + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/" + AmplificationHelper.PATH_SEPARATOR + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getTestClassesDir();
    DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath, new File(Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getTestClassesDir()));
    AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).runPit(Utils.getInputProgram().getProgramDir());
    final List<PitResult> amplifiedPitResults = PitResultParser.parseAndDelete(Utils.getInputProgram().getProgramDir() + "target/pit-reports/");
    assertTrue(pitResults.stream().filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED || pitResult.getStateOfMutant() == PitResult.State.SURVIVED).count() < amplifiedPitResults.stream().filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED || pitResult.getStateOfMutant() == PitResult.State.SURVIVED).count());
    Main.verbose = false;
}
Also used : TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) DSpotCompiler(fr.inria.diversify.utils.compilation.DSpotCompiler) DSpotUtils(fr.inria.diversify.utils.DSpotUtils) Main(fr.inria.stamp.Main) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DSpot(fr.inria.diversify.dspot.DSpot) File(java.io.File) List(java.util.List) CtType(spoon.reflect.declaration.CtType) Ignore(org.junit.Ignore) Utils(fr.inria.Utils) AutomaticBuilderFactory(fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory) PitResult(fr.inria.diversify.mutant.pit.PitResult) Collections(java.util.Collections) PitResultParser(fr.inria.diversify.mutant.pit.PitResultParser) Before(org.junit.Before) DSpot(fr.inria.diversify.dspot.DSpot) CtType(spoon.reflect.declaration.CtType) PitResult(fr.inria.diversify.mutant.pit.PitResult) File(java.io.File) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TestDataMutator

use of fr.inria.diversify.dspot.amplifier.TestDataMutator in project dspot by STAMP-project.

the class JacocoCoverageSelectorTest method testDSpotWithJacocoCoverageSelector.

@Test
public void testDSpotWithJacocoCoverageSelector() throws Exception {
    try {
        FileUtils.deleteDirectory(new File("target/trash"));
    } catch (Exception ignored) {
    // ignored
    }
    AmplificationHelper.setSeedRandom(23L);
    InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
    DSpot dspot = new DSpot(configuration, 2, Arrays.asList(new TestDataMutator(), new StatementAdd()), new JacocoCoverageSelector());
    dspot.amplifyTest("example.TestSuiteExample", Collections.singletonList("test2"));
    try (BufferedReader buffer = new BufferedReader(new FileReader(configuration.getOutputDirectory() + "example.TestSuiteExample_jacoco_instr_coverage_report.txt"))) {
        assertEquals(expectedReport, buffer.lines().collect(Collectors.joining(nl)));
    }
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) BufferedReader(java.io.BufferedReader) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) FileReader(java.io.FileReader) File(java.io.File) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Test(org.junit.Test)

Example 3 with TestDataMutator

use of fr.inria.diversify.dspot.amplifier.TestDataMutator in project dspot by STAMP-project.

the class ProjectJSONTest method test.

@Test
public void test() throws Exception {
    final File file = new File("target/trash/sample.json");
    if (file.exists()) {
        file.delete();
    }
    DSpot dspot = new DSpot(new InputConfiguration("src/test/resources/sample/sample.properties"), 1, Collections.singletonList(new TestDataMutator()), new JacocoCoverageSelector());
    dspot.amplifyTest("fr.inria.amp.TestJavaPoet");
    try (BufferedReader buffer = new BufferedReader(new FileReader(file))) {
        final String jsonAsString = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
        assertTrue(jsonAsString.startsWith(expectedFirstProjectJSON[0]));
        assertTrue(jsonAsString.endsWith(expectedFirstProjectJSON[1]));
    }
    dspot.amplifyTest("fr.inria.mutation.ClassUnderTestTest");
    try (BufferedReader buffer = new BufferedReader(new FileReader(file))) {
        final String jsonAsString = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
        assertTrue(jsonAsString.startsWith(expectedFirstProjectJSON[0]));
        assertTrue(jsonAsString.contains(expectedFirstProjectJSON[2]));
        assertTrue(jsonAsString.endsWith(expectedFirstProjectJSON[3]));
    }
    dspot.amplifyTest("fr.inria.amp.TestJavaPoet");
    try (BufferedReader buffer = new BufferedReader(new FileReader(file))) {
        final String jsonAsString = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
        assertTrue(jsonAsString.startsWith(expectedFirstProjectJSON[0]));
        assertTrue(jsonAsString.endsWith(expectedFirstProjectJSON[1]));
    }
}
Also used : JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Test(org.junit.Test)

Example 4 with TestDataMutator

use of fr.inria.diversify.dspot.amplifier.TestDataMutator in project dspot by STAMP-project.

the class Main method runExample.

static void runExample() {
    try {
        InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
        DSpot dSpot = new DSpot(configuration, 1, Collections.singletonList(new TestDataMutator()), new JacocoCoverageSelector());
        dSpot.amplifyTest("example.TestSuiteExample");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) IOException(java.io.IOException) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator)

Example 5 with TestDataMutator

use of fr.inria.diversify.dspot.amplifier.TestDataMutator in project dspot by STAMP-project.

the class DSpotTest method testInheritanceMethod.

@Test
public void testInheritanceMethod() throws Exception {
    /*
            Test that DSpot can be run on an abstract test, using its implementation.
         */
    final InputConfiguration configuration = new InputConfiguration("src/test/resources/sample/sample.properties");
    DSpot dspot = new DSpot(configuration, 3, Collections.singletonList(new TestDataMutator()), new JacocoCoverageSelector());
    CtType<?> ctType = dspot.amplifyTest("fr.inria.inheritance.Inherited").get(0);
    assertEquals(1, ctType.getMethods().size());
}
Also used : JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Aggregations

TestDataMutator (fr.inria.diversify.dspot.amplifier.TestDataMutator)5 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)4 Test (org.junit.Test)4 DSpot (fr.inria.diversify.dspot.DSpot)3 JacocoCoverageSelector (fr.inria.diversify.dspot.selector.JacocoCoverageSelector)3 File (java.io.File)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 AbstractTest (fr.inria.AbstractTest)1 Utils (fr.inria.Utils)1 AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)1 StatementAdd (fr.inria.diversify.dspot.amplifier.StatementAdd)1 PitResult (fr.inria.diversify.mutant.pit.PitResult)1 PitResultParser (fr.inria.diversify.mutant.pit.PitResultParser)1 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)1 DSpotUtils (fr.inria.diversify.utils.DSpotUtils)1 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)1 Main (fr.inria.stamp.Main)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1