use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class DSpotAndResourcesTest method test.
@Test
public void test() throws Exception {
/*
Contract: DSpot is able to run tests that are using resources.
This does not mean that referenced resources by relative-path is supported.
Developers should not point directly resources by relative path inside their test, but rather use API
such as getResourceAsStream()
*/
final CtClass<?> classUsingResources = Utils.findClass("fr.inria.testresources.TestResources");
final InputProgram program = Utils.getInputProgram();
final String classpath = program.getProgramDir() + program.getClassesDir() + PATH_SEPARATOR + program.getProgramDir() + program.getTestClassesDir() + PATH_SEPARATOR + Utils.getBuilder().buildClasspath(program.getProgramDir());
final TestListener result = TestLauncher.runFromSpoonNodes(Utils.getInputConfiguration(), classpath, classUsingResources, classUsingResources.getMethodsByName("testResources"));
assertTrue(result.getFailingTests().isEmpty());
assertEquals(1, result.getRunningTests().size());
}
use of fr.inria.diversify.utils.sosiefier.InputProgram 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());
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class StatementAddTest method testOnClassWithJavaObjects.
@Test
public void testOnClassWithJavaObjects() throws Exception {
/*
Test that the StatementAdd amplifier is able to generate, and manage Collection and Map from java.util
*/
final String packageName = "fr.inria.statementadd";
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 + ".ClassTarget"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
assertEquals(7, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("getList", "getSizeOf", "getSizeOfTypedCollection", "getSizeOfTypedMap");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class StatementAddTest method testStatementAddOnArrayObjects.
@Test
public void testStatementAddOnArrayObjects() 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);
System.out.println(amplifiedMethods);
assertEquals(5, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("methodWithArrayParatemeter", "methodWithArrayParatemeterFromDomain", "methodWithDomainParameter", "methodWithReturn", "method1");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class TestLauncherTest method testRunningAllKindOfTests.
@Test
public void testRunningAllKindOfTests() throws Exception {
Launcher launcher = new Launcher();
launcher.getEnvironment().setSourceClasspath(System.getProperty("java.class.path").split(System.getProperty("path.separator")));
launcher.addInputResource("src/test/resources/src/");
launcher.addInputResource("src/test/resources/test/");
launcher.buildModel();
final String classpath = "src/test/resources/MockitoDemo-1.0-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/MockitoDemo-1.0-SNAPSHOT-tests.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT-tests.jar";
/*
Test that we the same entry point we are able to run all kind of test
*/
InputConfiguration configuration = new InputConfiguration("src/test/resources/mockito/mockito.properties");
configuration.setInputProgram(new InputProgram());
// Mocked
TestListener results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest"));
assertEquals(5, results.getRunningTests().size());
assertEquals(1, results.getFailingTests().size());
assertEquals(4, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest"), Collections.singleton("testGetBook"));
assertEquals(1, results.getRunningTests().size());
assertEquals(0, results.getFailingTests().size());
assertEquals(1, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
configuration.setInputProgram(new InputProgram());
// Default
results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.TestSuiteExample"), Collections.singleton("test1"));
assertEquals(1, results.getRunningTests().size());
assertEquals(1, results.getFailingTests().size());
assertEquals(0, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
configuration = new InputConfiguration("src/test/resources/sample/sample.properties");
configuration.setInputProgram(new InputProgram());
// Abstract Class: using implementation of abstract class to run test
results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.InheriteTest"));
assertEquals(2, results.getRunningTests().size());
assertEquals(0, results.getFailingTests().size());
assertEquals(2, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
// will use example.InheriteTest to run the test of AbstractTest
results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.AbstractTest"), Collections.singleton("abstractTest"));
assertEquals(1, results.getRunningTests().size());
assertEquals(0, results.getFailingTests().size());
assertEquals(1, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.AbstractTest"));
assertEquals(2, results.getRunningTests().size());
assertEquals(0, results.getFailingTests().size());
assertEquals(2, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
}
Aggregations