Search in sources :

Example 11 with InputProgram

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());
}
Also used : TestListener(fr.inria.stamp.test.listener.TestListener) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 12 with InputProgram

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());
}
Also used : AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) File(java.io.File) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 13 with InputProgram

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));
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Arrays(java.util.Arrays) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) CtInvocation(spoon.reflect.code.CtInvocation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) List(java.util.List) Utils(fr.inria.Utils) CtClass(spoon.reflect.declaration.CtClass) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractTest(fr.inria.AbstractTest) CtMethod(spoon.reflect.declaration.CtMethod) Factory(spoon.reflect.factory.Factory) CtInvocation(spoon.reflect.code.CtInvocation) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 14 with InputProgram

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));
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Arrays(java.util.Arrays) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) CtInvocation(spoon.reflect.code.CtInvocation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) List(java.util.List) Utils(fr.inria.Utils) CtClass(spoon.reflect.declaration.CtClass) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractTest(fr.inria.AbstractTest) CtMethod(spoon.reflect.declaration.CtMethod) Factory(spoon.reflect.factory.Factory) CtInvocation(spoon.reflect.code.CtInvocation) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 15 with InputProgram

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());
}
Also used : Launcher(spoon.Launcher) TestListener(fr.inria.stamp.test.listener.TestListener) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test)

Aggregations

InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)30 Test (org.junit.Test)19 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)12 AbstractTest (fr.inria.AbstractTest)10 CtMethod (spoon.reflect.declaration.CtMethod)10 File (java.io.File)9 Factory (spoon.reflect.factory.Factory)7 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)6 List (java.util.List)6 IOException (java.io.IOException)5 CtClass (spoon.reflect.declaration.CtClass)5 Utils (fr.inria.Utils)4 Arrays (java.util.Arrays)4 Map (java.util.Map)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 CtInvocation (spoon.reflect.code.CtInvocation)4 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)4 AbstractTest (eu.stamp.project.ex2amplifier.AbstractTest)3 TestListener (fr.inria.stamp.test.listener.TestListener)3 Collectors (java.util.stream.Collectors)3