use of eu.stamp_project.dspot.common.configuration.DSpotState in project dspot by STAMP-project.
the class AbstractSelectorRemoveOverlapTest method testRemoveOverlappingTests.
@Test
public void testRemoveOverlappingTests() {
this.testSelectorUnderTest.init();
DSpotState dspotState = new DSpotState();
dspotState.setDelta(0.1f);
dspotState.setTestFinder(new TestFinder(Collections.emptyList(), Collections.emptyList()));
dspotState.setCompiler(compiler);
dspotState.setTestSelector(this.testSelectorUnderTest);
dspotState.setInputAmplDistributor(InputAmplDistributorEnum.RandomInputAmplDistributor.getInputAmplDistributor(200, Collections.singletonList(new StringLiteralAmplifier())));
dspotState.setOutput(new Output(getPathToAbsoluteProjectRoot(), configuration.getOutputDirectory(), new NullCollector()));
dspotState.setNbIteration(1);
dspotState.setAutomaticBuilder(builder);
dspotState.setTestCompiler(testCompiler);
dspotState.setTestClassesToBeAmplified(Collections.singletonList(getTestClass()));
dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
DSpot dspot = new DSpot(dspotState);
dspot.run();
final File directory = new File(DSpotUtils.shouldAddSeparator.apply(this.configuration.getOutputDirectory()));
if (!directory.exists()) {
directory.mkdir();
}
assertEquals(getContentReportFile(), this.testSelectorUnderTest.report().output(this.getTestClass(), this.outputDirectory));
}
use of eu.stamp_project.dspot.common.configuration.DSpotState in project dspot by STAMP-project.
the class ProjectJSONTest method test.
@Test
public void test() throws Exception {
final File file = new File(outputDirectory + "/sample.json");
if (file.exists()) {
file.delete();
}
final InputAmplDistributor inputAmplDistributor = InputAmplDistributorEnum.RandomInputAmplDistributor.getInputAmplDistributor(200, Collections.emptyList());
DSpotState dspotState = new DSpotState();
dspotState.setDelta(0.1f);
dspotState.setTestFinder(TestFinder.get());
dspotState.setCompiler(compiler);
dspotState.setTestSelector(testSelector);
dspotState.setInputAmplDistributor(inputAmplDistributor);
dspotState.setOutput(Output.get(configuration));
dspotState.setNbIteration(1);
dspotState.setAutomaticBuilder(builder);
dspotState.setTestCompiler(testCompiler);
dspotState.setTestClassesToBeAmplified(Collections.singletonList(findClass("fr.inria.amp.TestJavaPoet")));
dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
DSpot dspot = new DSpot(dspotState);
final CtClass<?> clone = findClass("fr.inria.amp.TestJavaPoet").clone();
dspot.run();
ProjectTimeJSON projectJson = getProjectJson(file);
assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> "fr.inria.amp.TestJavaPoet".equals(classTimeJSON.fullQualifiedName)));
assertEquals(1, projectJson.classTimes.size());
assertEquals("sample", projectJson.projectName);
dspotState.setTestClassesToBeAmplified(Collections.singletonList(findClass("fr.inria.mutation.ClassUnderTestTest")));
dspot.run();
projectJson = getProjectJson(file);
assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.amp.TestJavaPoet")));
assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.mutation.ClassUnderTestTest")));
assertEquals(2, projectJson.classTimes.size());
assertEquals("sample", projectJson.projectName);
/* we reinitialize the factory to remove the amplified test class */
final CtClass<?> amplifiedClassToBeRemoved = findClass("fr.inria.amp.TestJavaPoet");
final CtPackage aPackage = amplifiedClassToBeRemoved.getPackage();
aPackage.removeType(amplifiedClassToBeRemoved);
aPackage.addType(clone);
dspotState.setTestClassesToBeAmplified(Collections.singletonList(findClass("fr.inria.amp.TestJavaPoet")));
dspot.run();
projectJson = getProjectJson(file);
assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.amp.TestJavaPoet")));
assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.mutation.ClassUnderTestTest")));
assertEquals(2, projectJson.classTimes.size());
assertEquals("sample", projectJson.projectName);
}
use of eu.stamp_project.dspot.common.configuration.DSpotState in project dspot by STAMP-project.
the class RecoveryDSpotTest method testThatDSpotCanRecoverFromError.
@Test
public void testThatDSpotCanRecoverFromError() throws Exception {
/*
We test here, with different mock, that DSpot can recover for errors, continue and terminate the amplification process.
*/
final SelectorThatThrowsError selector = new SelectorThatThrowsError(builder, configuration);
selector.setThrowsToAmplify(true);
DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, "");
final TestFinder testFinder = new TestFinder(Collections.emptyList(), Collections.emptyList());
final CtClass<?> testClassToBeAmplified = findClass("fr.inria.amp.OneLiteralTest");
final List<CtMethod<?>> testListToBeAmplified = testFinder.findTestMethods(testClassToBeAmplified, Collections.emptyList());
DSpotState dspotState = new DSpotState();
dspotState.setDelta(0.1f);
dspotState.setCompiler(compiler);
dspotState.setTestSelector(selector);
dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, Collections.emptyList()));
dspotState.setNbIteration(1);
dspotState.setTestCompiler(testCompiler);
dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
DSpot dspot = new DSpot(dspotState);
dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
assertSame(ErrorEnum.ERROR_PRE_SELECTION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
DSpotState.GLOBAL_REPORT.reset();
selector.setThrowsToAmplify(false);
selector.setThrowsToKeep(true);
dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
assertSame(ErrorEnum.ERROR_SELECTION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
DSpotState.GLOBAL_REPORT.reset();
final List<Amplifier> amplifiers = Collections.singletonList(new AmplifierThatThrowsError());
dspotState.setTestSelector(new TakeAllSelector(this.builder, this.configuration));
dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, amplifiers));
dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
assertEquals(1, DSpotState.GLOBAL_REPORT.getErrors().size());
assertSame(ErrorEnum.ERROR_INPUT_AMPLIFICATION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
DSpotState.GLOBAL_REPORT.reset();
dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, Collections.emptyList()));
dspotState.setAssertionGenerator(new AssertionGeneratorThatThrowsError(compiler));
dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
assertEquals(1, DSpotState.GLOBAL_REPORT.getErrors().size());
assertSame(ErrorEnum.ERROR_ASSERT_AMPLIFICATION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
DSpotState.GLOBAL_REPORT.reset();
}
Aggregations