Search in sources :

Example 11 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class ProjectJSONTest method test.

@Test
public void test() throws Exception {
    final File file = new File("target/trash/sample.json");
    if (file.exists()) {
        file.delete();
    }
    DSpot dspot = new DSpot(new InputConfiguration("src/test/resources/sample/sample.properties"), 1, Collections.singletonList(new TestDataMutator()), new JacocoCoverageSelector());
    dspot.amplifyTest("fr.inria.amp.TestJavaPoet");
    try (BufferedReader buffer = new BufferedReader(new FileReader(file))) {
        final String jsonAsString = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
        assertTrue(jsonAsString.startsWith(expectedFirstProjectJSON[0]));
        assertTrue(jsonAsString.endsWith(expectedFirstProjectJSON[1]));
    }
    dspot.amplifyTest("fr.inria.mutation.ClassUnderTestTest");
    try (BufferedReader buffer = new BufferedReader(new FileReader(file))) {
        final String jsonAsString = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
        assertTrue(jsonAsString.startsWith(expectedFirstProjectJSON[0]));
        assertTrue(jsonAsString.contains(expectedFirstProjectJSON[2]));
        assertTrue(jsonAsString.endsWith(expectedFirstProjectJSON[3]));
    }
    dspot.amplifyTest("fr.inria.amp.TestJavaPoet");
    try (BufferedReader buffer = new BufferedReader(new FileReader(file))) {
        final String jsonAsString = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
        assertTrue(jsonAsString.startsWith(expectedFirstProjectJSON[0]));
        assertTrue(jsonAsString.endsWith(expectedFirstProjectJSON[1]));
    }
}
Also used : JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Test(org.junit.Test)

Example 12 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration 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)

Example 13 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class DSpotMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Configuration configuration = new Configuration(// path to file
    null, // Amplifiers
    JSAPOptions.buildAmplifiersFromString(getAmplifiers().toArray(new String[0])), // Iteration
    getIteration(), // testClases
    getNamesOfTestCases(), getOutputPath().toString(), SelectorEnum.valueOf(getSelector()).buildSelector(), getNamesOfTestCases(), getRandomSeed().longValue(), getTimeOutInMs().intValue(), BUILDER, getMavenHome().getAbsolutePath(), 10, false, false);
    InputConfiguration inputConfiguration;
    try {
        inputConfiguration = new InputConfiguration(getProject(), getSrcDir(), getTestDir(), getClassesDir(), getTestClassesDir(), getTempDir(), getFilter(), getMavenHome());
        Main.run(configuration, inputConfiguration);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) Configuration(fr.inria.stamp.Configuration) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 14 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration 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);
}
Also used : TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Logger(org.slf4j.Logger) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) SelectorOnDiff(fr.inria.stamp.diff.SelectorOnDiff) DSpot(fr.inria.diversify.dspot.DSpot) File(java.io.File) List(java.util.List) CtType(spoon.reflect.declaration.CtType) Collections(java.util.Collections) DSpot(fr.inria.diversify.dspot.DSpot) CtType(spoon.reflect.declaration.CtType) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram)

Example 15 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration 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);
    }
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) IOException(java.io.IOException) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator)

Aggregations

InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)25 Test (org.junit.Test)14 InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)11 JacocoCoverageSelector (fr.inria.diversify.dspot.selector.JacocoCoverageSelector)6 File (java.io.File)6 TestDataMutator (fr.inria.diversify.dspot.amplifier.TestDataMutator)5 DSpot (fr.inria.diversify.dspot.DSpot)4 AbstractTest (fr.inria.AbstractTest)3 IOException (java.io.IOException)3 Launcher (spoon.Launcher)3 CtType (spoon.reflect.declaration.CtType)3 StatementAdd (fr.inria.diversify.dspot.amplifier.StatementAdd)2 TestListener (fr.inria.stamp.test.listener.TestListener)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 Before (org.junit.Before)2 AutomaticBuilder (fr.inria.diversify.automaticbuilder.AutomaticBuilder)1 AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)1 NumberLiteralAmplifier (fr.inria.diversify.dspot.amplifier.NumberLiteralAmplifier)1 StringLiteralAmplifier (fr.inria.diversify.dspot.amplifier.StringLiteralAmplifier)1