use of spoon.reflect.declaration.CtMethod 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 spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class AssertGeneratorHelperTest method testCreateTestWithLogWithDuplicatedStatement.
@Test
public void testCreateTestWithLogWithDuplicatedStatement() throws Exception {
/*
test the creation of log with duplicates statement
*/
CtClass testClass = Utils.findClass("fr.inria.sample.TestClassWithoutAssert");
final CtMethod<?> test2 = (CtMethod<?>) testClass.getMethodsByName("test2").get(0);
final CtMethod<?> testWithLog = AssertGeneratorHelper.createTestWithLog(test2, "fr.inria.sample");
final String expectedMethod = "@org.junit.Test(timeout = 10000)" + AmplificationHelper.LINE_SEPARATOR + "public void test2_withlog() throws java.lang.Exception {" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.sample.ClassWithBoolean cl = new fr.inria.sample.ClassWithBoolean();" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.diversify.compare.ObjectLog.log(cl, \"cl\", \"test2__1\");" + AmplificationHelper.LINE_SEPARATOR + " cl.getFalse();" + AmplificationHelper.LINE_SEPARATOR + " cl.getFalse();" + AmplificationHelper.LINE_SEPARATOR + " cl.getFalse();" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.diversify.compare.ObjectLog.log(cl, \"cl\", \"test2__1___end\");" + AmplificationHelper.LINE_SEPARATOR + "}";
assertEquals(expectedMethod, testWithLog.toString());
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class MethodsAssertGeneratorTest method testBuildNewAssertWithComment.
@Test
public void testBuildNewAssertWithComment() throws Exception {
/*
Same as testBuildNewAssert but with Comment enabled
*/
DSpotUtils.withComment = true;
CtClass testClass = Utils.findClass("fr.inria.sample.TestClassWithoutAssert");
MethodsAssertGenerator mag = new MethodsAssertGenerator(testClass, Utils.getInputConfiguration(), Utils.getCompiler());
CtMethod test1 = Utils.findMethod("fr.inria.sample.TestClassWithoutAssert", "test1");
List<CtMethod<?>> test1_buildNewAssert = mag.generateAsserts(testClass, Collections.singletonList(test1));
assertEquals(expectedBodyWithComment, test1_buildNewAssert.get(0).getBody().toString());
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class MethodsAssertGeneratorTest method testAssertsOnMaps.
@Test
public void testAssertsOnMaps() throws Exception {
CtClass testClass = Utils.findClass("fr.inria.sample.TestClassWithoutAssert");
MethodsAssertGenerator mag = new MethodsAssertGenerator(testClass, Utils.getInputConfiguration(), Utils.getCompiler());
CtMethod test1 = Utils.findMethod("fr.inria.sample.TestClassWithoutAssert", "test3");
List<CtMethod<?>> test1_buildNewAssert = mag.generateAsserts(testClass, Collections.singletonList(test1));
assertEquals(expectedBodyWithMap, test1_buildNewAssert.get(0).getBody().toString());
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class MethodsAssertGeneratorTest method testMakeFailureTest.
@Test
public void testMakeFailureTest() throws Exception {
CtClass<?> testClass = Utils.findClass("fr.inria.filter.failing.FailingTest");
MethodsAssertGenerator mag = new MethodsAssertGenerator(testClass, Utils.getInputConfiguration(), Utils.getCompiler());
final CtMethod testAssertionError = Utils.findMethod("fr.inria.filter.failing.FailingTest", "testAssertionError");
final List<CtMethod<?>> generatedAssertion = mag.generateAsserts(testClass, Collections.singletonList(testAssertionError));
assertTrue(generatedAssertion.isEmpty());
}
Aggregations