use of fr.inria.diversify.dspot.DSpot 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;
}
use of fr.inria.diversify.dspot.DSpot 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)));
}
}
use of fr.inria.diversify.dspot.DSpot in project dspot by STAMP-project.
the class Main method run.
public static void run(Configuration configuration, InputConfiguration inputConfiguration) throws Exception {
AmplificationHelper.setSeedRandom(23L);
AmplificationHelper.minimize = configuration.minimize;
InputProgram program = new InputProgram();
inputConfiguration.setInputProgram(program);
inputConfiguration.getProperties().setProperty("automaticBuilderName", configuration.automaticBuilderName);
AmplificationHelper.MAX_NUMBER_OF_TESTS = configuration.maxTestAmplified;
if (configuration.mavenHome != null) {
inputConfiguration.getProperties().put("maven.home", configuration.mavenHome);
}
if (configuration.pathToOutput != null) {
inputConfiguration.getProperties().setProperty("outputDirectory", configuration.pathToOutput);
}
DSpot dspot = new DSpot(inputConfiguration, configuration.nbIteration, configuration.amplifiers, configuration.selector);
AmplificationHelper.setSeedRandom(configuration.seed);
AmplificationHelper.setTimeOutInMs(configuration.timeOutInMs);
createOutputDirectories(inputConfiguration, configuration.clean);
final long startTime = System.currentTimeMillis();
final List<CtType> amplifiedTestClasses;
if ("all".equals(configuration.testClasses.get(0))) {
amplifiedTestClasses = dspot.amplifyAllTests();
} else if ("diff".equals(configuration.testClasses.get(0))) {
amplifiedTestClasses = dspot.amplifyAllTests(SelectorOnDiff.findTestClassesAccordingToADiff(inputConfiguration));
} else {
if (configuration.testCases.isEmpty()) {
amplifiedTestClasses = dspot.amplifyAllTestsNames(configuration.testClasses);
} else {
amplifiedTestClasses = configuration.testClasses.stream().map(testClasses -> dspot.amplifyTest(testClasses, configuration.testCases)).collect(Collectors.toList());
}
}
LOGGER.info("Amplification {}.", amplifiedTestClasses.isEmpty() ? "failed" : "succeed");
final long elapsedTime = System.currentTimeMillis() - startTime;
LOGGER.info("Elapsed time {} ms", elapsedTime);
}
use of fr.inria.diversify.dspot.DSpot 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);
}
}
use of fr.inria.diversify.dspot.DSpot in project dspot by STAMP-project.
the class PitScoreMutantSelectorDescartesTest method testPitDescartesMode.
@Test
public void testPitDescartesMode() throws Exception {
/*
weak contract: this test should not throw any exception and end properly
the increase of the mutation score and the selection is delegated to dedicated test
here we test that the descartes mode runs
*/
assertFalse(PitMutantScoreSelector.descartesMode);
PitMutantScoreSelector.descartesMode = true;
PitMutantScoreSelector.pitVersion = "1.2.0";
InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
DSpot dspot = new DSpot(configuration, 1, Arrays.asList(new StringLiteralAmplifier(), new NumberLiteralAmplifier()), new PitMutantScoreSelector());
dspot.amplifyTest("example.TestSuiteExample", Collections.singletonList("test2"));
FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
assertTrue(PitMutantScoreSelector.descartesMode);
}
Aggregations