use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.
the class Main method applyMinimization.
public static List<CtMethod<?>> applyMinimization(List<CtMethod<?>> amplifiedTestMethodsToBeMinimized, CtType<?> amplifiedTestClass, UserInput configuration) {
Main.report.medianNbStatementBefore = Main.getMedian(amplifiedTestMethodsToBeMinimized.stream().map(ctMethod -> ctMethod.getElements(new TypeFilter<>(CtStatement.class))).map(List::size).collect(Collectors.toList()));
// 1 apply general minimization
if (configuration.isApplyAllPrettifiers() || configuration.isApplyGeneralMinimizer()) {
amplifiedTestMethodsToBeMinimized = Main.applyGivenMinimizer(new GeneralMinimizer(), amplifiedTestMethodsToBeMinimized);
// update the test class with minimized test methods
final ArrayList<CtMethod<?>> allMethods = new ArrayList<>(amplifiedTestClass.getMethods());
allMethods.stream().filter(TestFramework.get()::isTest).forEach(amplifiedTestClass::removeMethod);
amplifiedTestMethodsToBeMinimized.forEach(amplifiedTestClass::addMethod);
}
// 2 apply pit minimization
if (configuration.isApplyAllPrettifiers() || configuration.isApplyPitMinimizer()) {
final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
amplifiedTestMethodsToBeMinimized = Main.applyGivenMinimizer(new PitMutantMinimizer(amplifiedTestClass, automaticBuilder, configuration.getAbsolutePathToProjectRoot(), configuration.getClasspathClassesProject(), configuration.getAbsolutePathToTestClasses()), amplifiedTestMethodsToBeMinimized);
}
Main.report.medianNbStatementAfter = Main.getMedian(amplifiedTestMethodsToBeMinimized.stream().map(ctMethod -> ctMethod.getElements(new TypeFilter<>(CtStatement.class))).map(List::size).collect(Collectors.toList()));
return amplifiedTestMethodsToBeMinimized;
}
use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.
the class MavenAutomaticBuilderTest method testGetDependenciesOf.
@Test
public void testGetDependenciesOf() throws Exception {
UserInput configuration = new UserInput();
configuration.setAbsolutePathToProjectRoot(new File("src/test/resources/test-projects/").getAbsolutePath());
AutomaticBuilder builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
final String dependenciesOf = builder.buildClasspath();
assertTrue(dependenciesOf.contains("org" + System.getProperty("file.separator") + "hamcrest" + System.getProperty("file.separator") + "hamcrest-core" + System.getProperty("file.separator") + "1.3" + System.getProperty("file.separator") + "hamcrest-core-1.3.jar"));
assertTrue(dependenciesOf.contains("junit" + System.getProperty("file.separator") + "junit" + System.getProperty("file.separator") + "4.11" + System.getProperty("file.separator") + "junit-4.11.jar"));
}
use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.
the class Main method run.
public static List<CtMethod<?>> run(CtType<?> amplifiedTestClass, UserInput configuration) {
InitializeDSpot initializeDSpot = new InitializeDSpot();
final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
final String dependencies = initializeDSpot.completeDependencies(configuration, automaticBuilder);
final DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
configuration.setFactory(compiler.getLauncher().getFactory());
initializeDSpot.initHelpers(configuration);
final List<CtMethod<?>> testMethods = TestFramework.getAllTest(amplifiedTestClass);
Main.report.nbTestMethods = testMethods.size();
final List<CtMethod<?>> minimizedAmplifiedTestMethods;
// 1 minimize amplified test methods
if (configuration.isApplyAllPrettifiers() || configuration.isApplyGeneralMinimizer() || configuration.isApplyPitMinimizer()) {
minimizedAmplifiedTestMethods = applyMinimization(testMethods, amplifiedTestClass, configuration);
} else {
minimizedAmplifiedTestMethods = testMethods;
}
// 2 rename test methods
if (configuration.isApplyAllPrettifiers() || configuration.isRenameTestMethods()) {
applyCode2Vec(minimizedAmplifiedTestMethods, configuration);
}
// 3 rename local variables TODO train one better model
final List<CtMethod<?>> prettifiedTestMethods;
if (configuration.isApplyAllPrettifiers() || configuration.isRenameLocalVariables()) {
prettifiedTestMethods = applyContext2Name(minimizedAmplifiedTestMethods);
} else {
prettifiedTestMethods = minimizedAmplifiedTestMethods;
}
return prettifiedTestMethods;
}
use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.
the class TestCompilerTest method test.
@Test
public void test() {
final UserInput configuration = new UserInput();
configuration.setAbsolutePathToProjectRoot(getPathToProjectRoot());
final AutomaticBuilder builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
InitializeDSpot initializeDSpot = new InitializeDSpot();
String dependencies = initializeDSpot.completeDependencies(configuration, builder);
configuration.setDependencies(dependencies);
DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
CtClass<?> testClass = findClass("fr.inria.filter.failing.FailingTest");
final ArrayList<CtMethod<?>> methods = new ArrayList<>();
methods.add(findMethod(testClass, "testAssertionError"));
methods.add(findMethod(testClass, "testFailingWithException"));
DSpotUtils.init(CommentEnum.None, "target/dspot/", configuration.getFullClassPathWithExtraDependencies(), getPathToProjectRoot());
TestCompiler testCompiler = new TestCompiler(0, false, getPathToProjectRoot(), configuration.getClasspathClassesProject(), 10000, "", false);
assertTrue(testCompiler.compileRunAndDiscardUncompilableAndFailingTestMethods(testClass, methods, compiler).isEmpty());
testClass = findClass("fr.inria.filter.passing.PassingTest");
methods.clear();
methods.add(findMethod(testClass, "testAssertion"));
methods.add(findMethod(testClass, "testNPEExpected"));
methods.add(findMethod(testClass, "failingTestCase"));
assertEquals(2, testCompiler.compileRunAndDiscardUncompilableAndFailingTestMethods(testClass, methods, compiler).size());
}
use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.
the class Utils method init.
public static void init(UserInput configuration) {
InitializeDSpot initializeDSpot = new InitializeDSpot();
final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
final String dependencies = initializeDSpot.completeDependencies(configuration, automaticBuilder);
final DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
configuration.setFactory(compiler.getLauncher().getFactory());
initializeDSpot.initHelpers(configuration);
Utils.configuration = configuration;
}
Aggregations