Search in sources :

Example 1 with TestFinder

use of eu.stamp_project.dspot.common.configuration.test_finder.TestFinder 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));
}
Also used : DSpot(eu.stamp_project.dspot.DSpot) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) Output(eu.stamp_project.dspot.common.report.output.Output) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) File(java.io.File) NullCollector(eu.stamp_project.dspot.common.collector.NullCollector) Test(org.junit.Test)

Example 2 with TestFinder

use of eu.stamp_project.dspot.common.configuration.test_finder.TestFinder in project dspot by STAMP-project.

the class InitializeDSpot method init.

public void init(UserInput userInput) {
    this.DSpotState = new DSpotState();
    DSpotState.setUserInput(userInput);
    DSpotState.setOnlyInputAmplification(userInput.isOnlyInputAmplification());
    DSpotState.setDevFriendlyAmplification(userInput.isDevFriendlyAmplification());
    DSpotState.verbose = userInput.isVerbose();
    DSpotState.setStartTime(System.currentTimeMillis());
    DSpotState.setTestFinder(new TestFinder(Arrays.stream(userInput.getExcludedClasses().split(",")).collect(Collectors.toList()), Arrays.stream(userInput.getExcludedTestCases().split(",")).collect(Collectors.toList())));
    DSpotState.setAutomaticBuilder(userInput.getBuilderEnum().getAutomaticBuilder(userInput));
    final String dependencies = completeDependencies(userInput, DSpotState.getAutomaticBuilder());
    DSpotState.setCompiler(DSpotCompiler.createDSpotCompiler(userInput, dependencies));
    userInput.setFactory(DSpotState.getCompiler().getLauncher().getFactory());
    initHelpers(userInput);
    DSpotState.setTestCompiler(new TestCompiler(userInput.getNumberParallelExecutionProcessors(), userInput.shouldExecuteTestsInParallel(), userInput.getAbsolutePathToProjectRoot(), userInput.getClasspathClassesProject(), userInput.getTimeOutInMs(), userInput.getPreGoalsTestExecution(), userInput.shouldUseMavenToExecuteTest()));
    final EmailSender emailSender = new EmailSender(userInput.getSmtpUsername(), userInput.getSmtpPassword(), userInput.getSmtpHost(), userInput.getSmtpPort(), userInput.isSmtpAuth(), userInput.getSmtpTls());
    DSpotState.setCollector(CollectorFactory.build(userInput, emailSender));
    DSpotState.getCollector().reportInitInformation(userInput.getAmplifiers(), userInput.getSelector(), userInput.getNbIteration(), userInput.isGregorMode(), !userInput.isGregorMode(), userInput.getNumberParallelExecutionProcessors());
    DSpotState.setTestClassesToBeAmplified(DSpotState.getTestFinder().findTestClasses(userInput.getTestClasses()));
    DSpotState.setTestMethodsToBeAmplifiedNames(userInput.getTestCases());
    if (DSpotState.getTestMethodsToBeAmplifiedNames().size() == 1 && DSpotState.getTestMethodsToBeAmplifiedNames().get(0).isEmpty()) {
        DSpotState.getTestMethodsToBeAmplifiedNames().clear();
    }
    DSpotState.setTestSelector(userInput.getSelector().buildSelector(DSpotState.getAutomaticBuilder(), userInput));
    final List<Amplifier> amplifiers = userInput.getAmplifiers().stream().map(AmplifierEnum::getAmplifier).filter(Objects::nonNull).collect(Collectors.toList());
    DSpotState.setInputAmplDistributor(userInput.getInputAmplDistributor().getInputAmplDistributor(userInput.getMaxTestAmplified(), amplifiers));
    DSpotState.setOutput(new Output(userInput.getAbsolutePathToProjectRoot(), userInput.getOutputDirectory(), DSpotState.getCollector()));
    DSpotState.setAssertionGenerator(new AssertionGenerator(userInput.getDelta(), DSpotState.getCompiler(), DSpotState.getTestCompiler(), DSpotState.isDevFriendlyAmplification()));
    Checker.postChecking(userInput);
    DSpotState.setCollectData(true);
    DSpotState.setDelta(userInput.getDelta());
    DSpotState.setNbIteration(userInput.getNbIteration());
    DSpotState.verbose = userInput.isVerbose();
}
Also used : TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) Output(eu.stamp_project.dspot.common.report.output.Output) AmplifierEnum(eu.stamp_project.dspot.common.configuration.options.AmplifierEnum) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) EmailSender(eu.stamp_project.dspot.common.collector.smtp.EmailSender) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)

Example 3 with TestFinder

use of eu.stamp_project.dspot.common.configuration.test_finder.TestFinder in project dspot by STAMP-project.

the class RecoveryDSpotTest method testNoMatchingTestClasses.

@Test
public void testNoMatchingTestClasses() {
    final TestFinder testFinder = new TestFinder(Collections.emptyList(), Collections.emptyList());
    testFinder.findTestClasses(Collections.singletonList("this.is.not.a.correct.package"));
    assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_NO_TEST_COULD_BE_FOUND_MATCHING_REGEX, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    assertSame(ErrorEnum.ERROR_NO_TEST_COULD_BE_FOUND, DSpotState.GLOBAL_REPORT.getErrors().get(1).type);
}
Also used : TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) Test(org.junit.Test)

Example 4 with TestFinder

use of eu.stamp_project.dspot.common.configuration.test_finder.TestFinder 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();
}
Also used : AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) DSpotCompiler(eu.stamp_project.dspot.common.compilation.DSpotCompiler) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) TextualDistanceInputAmplDistributor(eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) TakeAllSelector(eu.stamp_project.dspot.selector.TakeAllSelector) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)4 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)3 Test (org.junit.Test)3 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)2 DSpotState (eu.stamp_project.dspot.common.configuration.DSpotState)2 Output (eu.stamp_project.dspot.common.report.output.Output)2 DSpot (eu.stamp_project.dspot.DSpot)1 TextualDistanceInputAmplDistributor (eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor)1 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)1 NullCollector (eu.stamp_project.dspot.common.collector.NullCollector)1 EmailSender (eu.stamp_project.dspot.common.collector.smtp.EmailSender)1 DSpotCompiler (eu.stamp_project.dspot.common.compilation.DSpotCompiler)1 TestCompiler (eu.stamp_project.dspot.common.compilation.TestCompiler)1 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)1 AmplifierEnum (eu.stamp_project.dspot.common.configuration.options.AmplifierEnum)1 TakeAllSelector (eu.stamp_project.dspot.selector.TakeAllSelector)1 File (java.io.File)1 CtMethod (spoon.reflect.declaration.CtMethod)1