Search in sources :

Example 1 with NullCollector

use of eu.stamp_project.dspot.common.collector.NullCollector in project dspot by STAMP-project.

the class DSpotUtilsTest method testPrintAmplifiedTestClass.

@Test
public void testPrintAmplifiedTestClass() throws Exception {
    final File javaFile = new File(outputDirectory.getAbsolutePath() + "/" + "example.TestSuiteExample".replaceAll("\\.", "\\/") + ".java");
    try {
        FileUtils.forceDelete(javaFile);
    } catch (IOException ignored) {
    // ignored
    }
    Launcher launcher = new Launcher();
    launcher.addInputResource("src/test/resources/test-projects/src/test/java/example/TestSuiteExample.java");
    launcher.getEnvironment().setNoClasspath(true);
    launcher.buildModel();
    final CtType<?> type = launcher.getFactory().Type().get("example.TestSuiteExample");
    assertFalse(javaFile.exists());
    DSpotUtils.printAndCompileToCheck(type, outputDirectory, new NullCollector());
    assertTrue(javaFile.exists());
    final CtMethod<?> clone = type.getMethods().stream().findFirst().get().clone();
    final int nbMethodStart = type.getMethods().size();
    type.getMethods().forEach(type::removeMethod);
    clone.setSimpleName("MyNewMethod");
    type.addMethod(clone);
    DSpotUtils.printAndCompileToCheck(type, outputDirectory, new NullCollector());
    launcher = new Launcher();
    launcher.addInputResource(outputDirectory.getAbsolutePath() + "/" + "example.TestSuiteExample".replaceAll("\\.", "\\/") + ".java");
    launcher.getEnvironment().setNoClasspath(true);
    launcher.buildModel();
    assertEquals(nbMethodStart + 1, launcher.getFactory().Class().get("example.TestSuiteExample").getMethods().size());
    type.getMethods().forEach(type::removeMethod);
    clone.setSimpleName("MyNewMethod2");
    type.addMethod(clone);
    DSpotUtils.printAndCompileToCheck(type, outputDirectory, new NullCollector());
    launcher = new Launcher();
    launcher.addInputResource(outputDirectory.getAbsolutePath() + "/" + "example.TestSuiteExample".replaceAll("\\.", "\\/") + ".java");
    launcher.getEnvironment().setNoClasspath(true);
    launcher.buildModel();
    assertEquals(nbMethodStart + 2, launcher.getFactory().Class().get("example.TestSuiteExample").getMethods().size());
}
Also used : Launcher(spoon.Launcher) IOException(java.io.IOException) File(java.io.File) NullCollector(eu.stamp_project.dspot.common.collector.NullCollector) Test(org.junit.Test)

Example 2 with NullCollector

use of eu.stamp_project.dspot.common.collector.NullCollector 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)

Aggregations

NullCollector (eu.stamp_project.dspot.common.collector.NullCollector)2 File (java.io.File)2 Test (org.junit.Test)2 DSpot (eu.stamp_project.dspot.DSpot)1 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)1 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)1 DSpotState (eu.stamp_project.dspot.common.configuration.DSpotState)1 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)1 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)1 Output (eu.stamp_project.dspot.common.report.output.Output)1 IOException (java.io.IOException)1 Launcher (spoon.Launcher)1