use of fr.inria.diversify.dspot.amplifier.StatementAdd in project dspot by STAMP-project.
the class AssertGeneratorHelperTest method testNoInstrumentationOnGeneratedObject.
/**
* this test aims at verifying that dspot does not generate assertion for generated object.
* To do this, it will check that the instrumentation does not add observation points on those objects.
* If no observation point is added, any assertion would be generated.
*/
@Test
public void testNoInstrumentationOnGeneratedObject() throws Exception {
final String packageName = "fr.inria.statementaddarray";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
final List<CtMethod<?>> instrumentedAmplifiedTests = amplifiedMethods.stream().map(method -> AssertGeneratorHelper.createTestWithLog(method, "fr.inria.statementaddarray")).collect(Collectors.toList());
assertEquals(5, amplifiedMethods.size());
final String expectedInstrumentedBodyAfterAmplification_test_sd6_withlog = "{" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.statementaddarray.ClassTargetAmplify clazz = new fr.inria.statementaddarray.ClassTargetAmplify();" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.diversify.compare.ObjectLog.log(clazz, \"clazz\", \"test_sd6__1\");" + AmplificationHelper.LINE_SEPARATOR + " // StatementAdd: generate variable from return value" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.statementaddarray.ClassParameterAmplify __DSPOT_invoc_3 = clazz.methodWithReturn();" + AmplificationHelper.LINE_SEPARATOR + " // StatementAdd: add invocation of a method" + AmplificationHelper.LINE_SEPARATOR + " __DSPOT_invoc_3.method1();" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.diversify.compare.ObjectLog.log(clazz, \"clazz\", \"test_sd6__1___end\");" + AmplificationHelper.LINE_SEPARATOR + "}";
assertEquals(expectedInstrumentedBodyAfterAmplification_test_sd6_withlog, instrumentedAmplifiedTests.stream().filter(ctMethod1 -> "test_sd6_withlog".equals(ctMethod1.getSimpleName())).findFirst().get().getBody().toString());
}
use of fr.inria.diversify.dspot.amplifier.StatementAdd 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.amplifier.StatementAdd in project dspot by STAMP-project.
the class DSpotMockedTest method test.
@Test
public void test() throws Exception {
/*
Test the whole dspot procedure.
*/
ValueCreator.count = 0;
AmplificationHelper.setSeedRandom(23L);
InputConfiguration configuration = new InputConfiguration(getPathToPropertiesFile());
InputProgram program = new InputProgram();
configuration.setInputProgram(program);
DSpot dspot = new DSpot(configuration, 1, Arrays.asList(new StatementAdd()));
try {
FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
} catch (Exception ignored) {
}
assertEquals(6, dspot.getInputProgram().getFactory().Class().get("info.sanaulla.dal.BookDALTest").getMethods().size());
CtType<?> amplifiedTest = dspot.amplifyTest("info.sanaulla.dal.BookDALTest", Collections.singletonList("testGetBook"));
assertEquals(1, amplifiedTest.getMethods().stream().filter(AmplificationChecker::isTest).count());
System.out.println(amplifiedTest);
assertTrue(!amplifiedTest.getMethodsByName("testGetBook_sd8").isEmpty());
}
Aggregations