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]));
}
}
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());
}
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();
}
}
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);
}
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);
}
}
Aggregations