Skip to content

Commit

Permalink
feat: output now the original test class with original test method th…
Browse files Browse the repository at this point in the history
…at have been successfully amplified (#915)
  • Loading branch information
danglotb committed Oct 22, 2019
1 parent b8a43ea commit a993411
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import eu.stamp_project.Main;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.utils.DSpotUtils;
import eu.stamp_project.utils.collector.Collector;
Expand Down Expand Up @@ -72,11 +73,35 @@ public CtType<?> output(CtType<?> testClassToBeAmplified, List<CtMethod<?>> ampl
LOGGER.warn("DSpot could not obtain any amplified test method.");
LOGGER.warn("You can customize the following options: --amplifiers, --test-criterion, --iteration, --inputAmplDistributor etc, and retry with a new configuration.");
}

this.writeProjectTimeJSON();
// output the original test class with original test methods
outputSeedTestClassWithSuccessTestMethods(testClassToBeAmplified, amplifiedTestMethods);
return amplification;
}

private void outputSeedTestClassWithSuccessTestMethods(CtType<?> testClassToBeAmplified,
List<CtMethod<?>> amplifiedTestMethods) {
final CtType<?> clone = testClassToBeAmplified.clone();
testClassToBeAmplified.getPackage().addType(clone);
clone.getMethods().stream()
.filter(TestFramework.get()::isTest)
.forEach(clone::removeMethod);
amplifiedTestMethods.stream()
.map(AmplificationHelper::getOriginalTestMethod)
.distinct()
.forEach(clone::addMethod);
final File outputDirectory = new File(this.outputPathDirectory + "/original/");
Main.GLOBAL_REPORT.addNumberAmplifiedTestMethodsToTotal(amplifiedTestMethods.size());
Main.GLOBAL_REPORT.addPrintedTestClasses(
String.format("Print %s with %d amplified test cases in %s",
clone.getQualifiedName() + ".java",
amplifiedTestMethods.size(),
this.outputPathDirectory + "/original/"
)
);
DSpotUtils.printCtTypeToGivenDirectory(clone, outputDirectory, true);
}

private void writeProjectTimeJSON() {
final File file1 = new File(this.outputPathDirectory);
if (!file1.exists()) {
Expand Down
1 change: 1 addition & 0 deletions dspot/src/test/java/eu/stamp_project/MainTest.java
Expand Up @@ -228,6 +228,7 @@ public void testExample() throws Exception {
String content = reader.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
System.out.println(content);
assertTrue(content.startsWith(expectedAmplifiedTestClass));
assertTrue(new File("target/dspot/output/original/example/TestSuiteExample.java").exists());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit a993411

Please sign in to comment.