From ddf3c97682201360fff47daa14d2175f4b9f2f4a Mon Sep 17 00:00:00 2001 From: Benjamin DANGLOT Date: Fri, 9 Mar 2018 13:50:54 +0100 Subject: [PATCH] Change detector minimization (#354) * test: add a test on ChangeMinimizer * feat: add ChangeMinimizer, that will keep assertion that make the test fail * docs: add todos and docs * test: remove all useless call to reset() * checkstyle: remove unused imports --- .../selector/ChangeDetectorSelector.java | 10 +- .../stamp/minimization/ChangeMinimizer.java | 131 ++++++++++++++++++ .../stamp/minimization/GeneralMinimizer.java | 6 +- .../inria/stamp/minimization/Minimizer.java | 2 +- .../test/java/fr/inria/diversify/Utils.java | 3 +- .../MavenAutomaticBuilderTest.java | 2 - .../inria/diversify/dspot/AbstractTest.java | 5 - .../diversify/dspot/MavenAbstractTest.java | 1 - .../diversify/dspot/ProjectJSONTest.java | 7 - .../MethodsAssertGeneratorTest.java | 2 - .../dspot/inheritance/InheritanceTest.java | 7 - .../selector/ChangeDetectorSelectorTest.java | 2 - .../selector/CloverCoverageSelectorTest.java | 1 - .../selector/ExecutedMutantSelectorTest.java | 1 - .../inria/diversify/mutant/pit/PitTest.java | 1 + .../stamp/coverage/TestJacocoExecutor.java | 15 -- .../minimization/ChangeMinimizerTest.java | 84 +++++++++++ .../stamp/test/launcher/TestLauncherTest.java | 4 - 18 files changed, 228 insertions(+), 56 deletions(-) create mode 100644 dspot/src/main/java/fr/inria/stamp/minimization/ChangeMinimizer.java create mode 100644 dspot/src/test/java/fr/inria/stamp/minimization/ChangeMinimizerTest.java diff --git a/dspot/src/main/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelector.java b/dspot/src/main/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelector.java index 7c4f294b2..d2a0c2715 100644 --- a/dspot/src/main/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelector.java +++ b/dspot/src/main/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelector.java @@ -8,7 +8,7 @@ import fr.inria.diversify.utils.Initializer; import fr.inria.diversify.utils.sosiefier.InputConfiguration; import fr.inria.diversify.utils.sosiefier.InputProgram; -import fr.inria.stamp.minimization.GeneralMinimizer; +import fr.inria.stamp.minimization.ChangeMinimizer; import fr.inria.stamp.minimization.Minimizer; import fr.inria.stamp.test.launcher.TestLauncher; import fr.inria.stamp.test.listener.TestListener; @@ -66,7 +66,7 @@ public void init(InputConfiguration configuration) { DSpotUtils.shouldAddSeparator.apply(pathToFolder) : ""); inputProgram.setProgramDir(this.pathToChangedVersionOfProgram); - Initializer.initialize(configuration, inputProgram); + Initializer.initialize(inputConfiguration, inputProgram); } catch (Exception e) { throw new RuntimeException(e); } @@ -138,7 +138,11 @@ public List> getAmplifiedTestCases() { @Override public Minimizer getMinimizer() { - return new GeneralMinimizer(); + return new ChangeMinimizer(this.currentClassTestToBeAmplified, + this.configuration, this.program, + this.pathToChangedVersionOfProgram, + this.failurePerAmplifiedTest + ); } protected void reset() { diff --git a/dspot/src/main/java/fr/inria/stamp/minimization/ChangeMinimizer.java b/dspot/src/main/java/fr/inria/stamp/minimization/ChangeMinimizer.java new file mode 100644 index 000000000..4b0d95639 --- /dev/null +++ b/dspot/src/main/java/fr/inria/stamp/minimization/ChangeMinimizer.java @@ -0,0 +1,131 @@ +package fr.inria.stamp.minimization; + +import edu.emory.mathcs.backport.java.util.Collections; +import fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory; +import fr.inria.diversify.dspot.support.DSpotCompiler; +import fr.inria.diversify.utils.AmplificationChecker; +import fr.inria.diversify.utils.AmplificationHelper; +import fr.inria.diversify.utils.DSpotUtils; +import fr.inria.diversify.utils.sosiefier.InputConfiguration; +import fr.inria.diversify.utils.sosiefier.InputProgram; +import fr.inria.stamp.test.launcher.TestLauncher; +import org.junit.runner.notification.Failure; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import spoon.reflect.code.CtInvocation; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.declaration.CtType; +import spoon.reflect.visitor.filter.TypeFilter; + +import java.io.File; +import java.util.List; +import java.util.Map; + +/** + * Created by Benjamin DANGLOT + * benjamin.danglot@inria.fr + * on 07/03/18 + */ +public class ChangeMinimizer extends GeneralMinimizer { + + private static final Logger LOGGER = LoggerFactory.getLogger(ChangeMinimizer.class); + + private CtType testClass; + + private InputConfiguration configuration; + + private InputProgram program; + + private String pathToChangedVersionOfProgram; + + private Map, Failure> failurePerAmplifiedTest; + + private String classpath; + + public ChangeMinimizer(CtType testClass, + InputConfiguration configuration, + InputProgram program, + String pathToChangedVersionOfProgram, + Map, Failure> failurePerAmplifiedTest) { + this.testClass = testClass; + this.configuration = configuration; + this.program = program; + this.pathToChangedVersionOfProgram = pathToChangedVersionOfProgram; + this.failurePerAmplifiedTest = failurePerAmplifiedTest; + this.classpath = AutomaticBuilderFactory + .getAutomaticBuilder(this.configuration) + .buildClasspath(this.program.getProgramDir()) + + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/"; + } + + @Override + public CtMethod minimize(CtMethod amplifiedTestToBeMinimized) { + final CtMethod generalMinimize = super.minimize(amplifiedTestToBeMinimized); + final CtMethod changeMinimize = generalMinimize.clone(); + final long time = System.currentTimeMillis(); + final Failure failureToKeep = this.failurePerAmplifiedTest.get(amplifiedTestToBeMinimized); + changeMinimize.getElements(new TypeFilter(CtInvocation.class) { + @Override + public boolean matches(CtInvocation element) { + return AmplificationChecker.isAssert(element); + } + }).forEach(invocation -> + tryToRemoveAssertion(changeMinimize, + invocation, + failureToKeep + ) + ); + LOGGER.info("Reduce {}, {} statements to {} statements in {} ms.", + amplifiedTestToBeMinimized.getSimpleName(), + generalMinimize.getBody().getStatements().size(), + changeMinimize .getBody().getStatements().size(), + System.currentTimeMillis() - time + ); + return changeMinimize; + } + + private void tryToRemoveAssertion(CtMethod amplifiedTestToBeMinimized, + CtInvocation invocation, + Failure failureToKeep) { + final CtMethod clone = amplifiedTestToBeMinimized.clone(); + clone.getBody().removeStatement(invocation); + if (checkIfMinimizationIsOk(clone, failureToKeep)) { + amplifiedTestToBeMinimized.getBody().removeStatement(invocation); + } + } + + private boolean checkIfMinimizationIsOk(CtMethod amplifiedTestToBeMinimized, Failure failure) { + CtType clone = this.testClass.clone(); + // must compile + if (!printAndCompile(clone, amplifiedTestToBeMinimized)) { + return false; + } + // must have (the same?) failure + final List failingTests = TestLauncher.run(this.configuration, + classpath + + AmplificationHelper.PATH_SEPARATOR + + this.pathToChangedVersionOfProgram + "/" + this.program.getClassesDir() + + AmplificationHelper.PATH_SEPARATOR + + this.pathToChangedVersionOfProgram + "/" + this.program.getTestClassesDir(), + clone, + Collections.singletonList(amplifiedTestToBeMinimized.getSimpleName())) + .getFailingTests(); + return !failingTests.isEmpty();// && failingTests.get(0).equals(failure); + } + + private boolean printAndCompile(CtType clone, CtMethod amplifiedTestToBeMinimized) { + clone.setParent(this.testClass.getParent()); + this.testClass.getMethods().stream() + .filter(AmplificationChecker::isTest) + .forEach(clone::removeMethod); + clone.addMethod(amplifiedTestToBeMinimized); + DSpotUtils.printCtTypeToGivenDirectory(clone, new File(DSpotCompiler.pathToTmpTestSources)); + return DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, + classpath + + AmplificationHelper.PATH_SEPARATOR + + this.program.getProgramDir() + "/" + this.program.getClassesDir() + + AmplificationHelper.PATH_SEPARATOR + + this.program.getProgramDir() + "/" + this.program.getTestClassesDir(), + new File(this.pathToChangedVersionOfProgram + "/" + this.program.getTestClassesDir())); + } +} diff --git a/dspot/src/main/java/fr/inria/stamp/minimization/GeneralMinimizer.java b/dspot/src/main/java/fr/inria/stamp/minimization/GeneralMinimizer.java index be2b9582b..e133e0f29 100644 --- a/dspot/src/main/java/fr/inria/stamp/minimization/GeneralMinimizer.java +++ b/dspot/src/main/java/fr/inria/stamp/minimization/GeneralMinimizer.java @@ -51,9 +51,8 @@ public boolean matches(CtVariableRead element) { .filter(localVariable -> variableReads.stream() .map(CtVariableRead::getVariable) - .filter(variableRead -> - variableRead.equals(localVariable.getReference()) - ).count() == 1 + .filter(variableRead -> variableRead.equals(localVariable.getReference())) + .count() == 1 ).map(localVariable -> { variableReads.stream() .filter(variableRead -> @@ -63,6 +62,7 @@ public boolean matches(CtVariableRead element) { .replace(localVariable.getAssignment().clone()); return localVariable; }).forEach(amplifiedTestToBeMinimized.getBody()::removeStatement); + //TODO we can inline all local variables that are used only in assertion } } diff --git a/dspot/src/main/java/fr/inria/stamp/minimization/Minimizer.java b/dspot/src/main/java/fr/inria/stamp/minimization/Minimizer.java index b80c6fefa..dc9e24fcc 100644 --- a/dspot/src/main/java/fr/inria/stamp/minimization/Minimizer.java +++ b/dspot/src/main/java/fr/inria/stamp/minimization/Minimizer.java @@ -12,7 +12,7 @@ public interface Minimizer { /** * this method aims to remove all useless statement according to a given test criterion * @param amplifiedTestToBeMinimized - * @return + * @return a minimized version of amplifiedTestToBeMinimized */ CtMethod minimize(CtMethod amplifiedTestToBeMinimized); diff --git a/dspot/src/test/java/fr/inria/diversify/Utils.java b/dspot/src/test/java/fr/inria/diversify/Utils.java index 08f136795..c41515bd4 100644 --- a/dspot/src/test/java/fr/inria/diversify/Utils.java +++ b/dspot/src/test/java/fr/inria/diversify/Utils.java @@ -49,9 +49,8 @@ public static AutomaticBuilder getBuilder() { return builder; } - @Deprecated public static void reset() { - + currentInputConfigurationLoaded = null; } public static void init(String pathToConfFile) { diff --git a/dspot/src/test/java/fr/inria/diversify/automaticbuilder/MavenAutomaticBuilderTest.java b/dspot/src/test/java/fr/inria/diversify/automaticbuilder/MavenAutomaticBuilderTest.java index 6bb96efa5..10111f19a 100644 --- a/dspot/src/test/java/fr/inria/diversify/automaticbuilder/MavenAutomaticBuilderTest.java +++ b/dspot/src/test/java/fr/inria/diversify/automaticbuilder/MavenAutomaticBuilderTest.java @@ -29,7 +29,6 @@ public class MavenAutomaticBuilderTest { @Before public void setUp() throws Exception { - Utils.reset(); Main.verbose = true; MavenPitCommandAndOptions.evosuiteMode = false; MavenPitCommandAndOptions.descartesMode = false; @@ -37,7 +36,6 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { - Utils.reset(); Main.verbose = false; } diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/AbstractTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/AbstractTest.java index c0fe7f84f..57827c71b 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/AbstractTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/AbstractTest.java @@ -29,9 +29,4 @@ public void setUp() throws Exception { AmplificationHelper.setSeedRandom(72L); ValueCreator.count = 0; } - - @After - public void tearDown() throws Exception { - Utils.reset(); - } } diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/MavenAbstractTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/MavenAbstractTest.java index ebecdf183..4cfcc9299 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/MavenAbstractTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/MavenAbstractTest.java @@ -21,7 +21,6 @@ public abstract class MavenAbstractTest { @Before public void setUp() throws Exception { - Utils.reset(); try { FileUtils.forceDelete(new File("target/dspot/")); } catch (Exception ignored) { diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/ProjectJSONTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/ProjectJSONTest.java index 0bee9e345..d4c5a6ab4 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/ProjectJSONTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/ProjectJSONTest.java @@ -1,11 +1,9 @@ package fr.inria.diversify.dspot; -import fr.inria.diversify.Utils; import fr.inria.diversify.dspot.amplifier.TestDataMutator; import fr.inria.diversify.dspot.selector.JacocoCoverageSelector; import fr.inria.diversify.utils.sosiefier.InputConfiguration; import org.apache.commons.io.FileUtils; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -34,11 +32,6 @@ public void setUp() throws Exception { } } - @After - public void tearDown() throws Exception { - Utils.reset(); - } - @Test public void test() throws Exception { diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/assertGenerator/MethodsAssertGeneratorTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/assertGenerator/MethodsAssertGeneratorTest.java index af4ee4394..6559e93bc 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/assertGenerator/MethodsAssertGeneratorTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/assertGenerator/MethodsAssertGeneratorTest.java @@ -30,10 +30,8 @@ public void setUp() throws Exception { super.setUp(); } - @Override @After public void tearDown() throws Exception { - super.tearDown(); Main.verbose = false; } diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/inheritance/InheritanceTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/inheritance/InheritanceTest.java index 2a3139cc9..d04ca9846 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/inheritance/InheritanceTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/inheritance/InheritanceTest.java @@ -1,11 +1,9 @@ package fr.inria.diversify.dspot.inheritance; -import fr.inria.diversify.Utils; import fr.inria.diversify.dspot.DSpot; import fr.inria.diversify.dspot.amplifier.TestDataMutator; import fr.inria.diversify.dspot.selector.JacocoCoverageSelector; import fr.inria.diversify.utils.sosiefier.InputConfiguration; -import org.junit.Before; import org.junit.Test; import spoon.reflect.declaration.CtType; @@ -21,11 +19,6 @@ */ public class InheritanceTest { - @Before - public void setUp() throws Exception { - Utils.reset(); - } - @Test public void testInheritanceMethod() throws Exception { final InputConfiguration configuration = new InputConfiguration("src/test/resources/sample/sample.properties"); diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelectorTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelectorTest.java index 71cae7555..6adbf0c1e 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelectorTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/selector/ChangeDetectorSelectorTest.java @@ -12,9 +12,7 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; -import java.util.Arrays; import java.util.Collections; import java.util.stream.Collectors; diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/selector/CloverCoverageSelectorTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/selector/CloverCoverageSelectorTest.java index ff1472a52..38d36982c 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/selector/CloverCoverageSelectorTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/selector/CloverCoverageSelectorTest.java @@ -27,7 +27,6 @@ public void test() throws Exception { This selector aims at keeping amplified test that execute new lines in the source code. */ - Utils.reset(); Utils.init("src/test/resources/test-projects/test-projects.properties"); EntryPoint.verbose = true; diff --git a/dspot/src/test/java/fr/inria/diversify/dspot/selector/ExecutedMutantSelectorTest.java b/dspot/src/test/java/fr/inria/diversify/dspot/selector/ExecutedMutantSelectorTest.java index e0e7f0122..b8d600657 100644 --- a/dspot/src/test/java/fr/inria/diversify/dspot/selector/ExecutedMutantSelectorTest.java +++ b/dspot/src/test/java/fr/inria/diversify/dspot/selector/ExecutedMutantSelectorTest.java @@ -29,7 +29,6 @@ public class ExecutedMutantSelectorTest { @Before public void setUp() throws Exception { - Utils.reset(); Utils.init("src/test/resources/test-projects/test-projects.properties"); } diff --git a/dspot/src/test/java/fr/inria/diversify/mutant/pit/PitTest.java b/dspot/src/test/java/fr/inria/diversify/mutant/pit/PitTest.java index f244f08de..9e9dec113 100644 --- a/dspot/src/test/java/fr/inria/diversify/mutant/pit/PitTest.java +++ b/dspot/src/test/java/fr/inria/diversify/mutant/pit/PitTest.java @@ -65,6 +65,7 @@ public void testPit() throws Exception { Run the PitRunner on the test-project example. Checks that the PitRunner return well the results, and verify state of mutant. */ + Utils.reset(); AmplificationHelper.setSeedRandom(23L); MavenPitCommandAndOptions.descartesMode = false; MavenPitCommandAndOptions.evosuiteMode = false; diff --git a/dspot/src/test/java/fr/inria/stamp/coverage/TestJacocoExecutor.java b/dspot/src/test/java/fr/inria/stamp/coverage/TestJacocoExecutor.java index 99946a67e..52bdfb928 100644 --- a/dspot/src/test/java/fr/inria/stamp/coverage/TestJacocoExecutor.java +++ b/dspot/src/test/java/fr/inria/stamp/coverage/TestJacocoExecutor.java @@ -17,19 +17,8 @@ */ public class TestJacocoExecutor { - @Before - public void setUp() throws Exception { - Utils.reset(); - } - - @After - public void tearDown() throws Exception { - Utils.reset(); - } - @Test public void testJacocoExecutorOnJMockit() throws Exception { - Utils.reset(); Utils.init("src/test/resources/jmockit/mock.properties"); final CtClass jmockitTest = Utils.findClass("org.baeldung.mocks.jmockit.LoginControllerIntegrationTest"); @@ -43,7 +32,6 @@ public void testJacocoExecutorOnJMockit() throws Exception { @Test public void testJacocoExecutorOnEasyMock() throws Exception { - Utils.reset(); Utils.init("src/test/resources/easymock/mock.properties"); final CtClass easyMockTest = Utils.findClass("org.baeldung.mocks.easymock.LoginControllerIntegrationTest"); @@ -57,7 +45,6 @@ public void testJacocoExecutorOnEasyMock() throws Exception { @Test public void testJacocoExecutor() throws Exception { - Utils.reset(); Utils.init("src/test/resources/test-projects/test-projects.properties"); final CtClass testClass = Utils.findClass("example.TestSuiteExample"); JacocoExecutor jacocoExecutor = new JacocoExecutor(Utils.getInputProgram(), Utils.getInputConfiguration(), testClass); @@ -73,7 +60,6 @@ public void testJacocoExecutor() throws Exception { @Test @Ignore public void testJacocoExecutorOnMockito() throws Exception { - Utils.reset(); Utils.init("src/test/resources/mockito/mockito.properties"); final CtClass testClass = Utils.findClass("info.sanaulla.dal.BookDALTest"); JacocoExecutor jacocoExecutor = new JacocoExecutor(Utils.getInputProgram(), Utils.getInputConfiguration(), testClass); @@ -89,7 +75,6 @@ public void testJacocoExecutorOnMockito() throws Exception { @Test @Ignore public void testJacocoExecutorOnMockito2() throws Exception { - Utils.reset(); Utils.init("src/test/resources/mockito2/mock.properties"); final CtClass mockitoTest = Utils.findClass("org.baeldung.mocks.mockito.LoginControllerIntegrationTest"); diff --git a/dspot/src/test/java/fr/inria/stamp/minimization/ChangeMinimizerTest.java b/dspot/src/test/java/fr/inria/stamp/minimization/ChangeMinimizerTest.java new file mode 100644 index 000000000..e70b9aee0 --- /dev/null +++ b/dspot/src/test/java/fr/inria/stamp/minimization/ChangeMinimizerTest.java @@ -0,0 +1,84 @@ +package fr.inria.stamp.minimization; + +import fr.inria.diversify.Utils; +import fr.inria.diversify.dspot.AbstractTest; +import fr.inria.diversify.utils.AmplificationChecker; +import fr.inria.diversify.utils.DSpotUtils; +import fr.inria.diversify.utils.Initializer; +import fr.inria.diversify.utils.sosiefier.InputConfiguration; +import fr.inria.diversify.utils.sosiefier.InputProgram; +import org.junit.Test; +import org.junit.runner.notification.Failure; +import spoon.reflect.code.CtInvocation; +import spoon.reflect.code.CtLiteral; +import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.visitor.filter.TypeFilter; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + +/** + * Created by Benjamin DANGLOT + * benjamin.danglot@inria.fr + * on 07/03/18 + */ +public class ChangeMinimizerTest extends AbstractTest { + + @Override + public String getPathToPropertiesFile() { + return "src/test/resources/regression/test-projects_0/test-projects.properties"; + } + + @Test + public void test() throws Exception { + + /* + + */ + + final CtClass testClass = Utils.findClass("example.TestSuiteExample"); + final String configurationPath = Utils.getInputConfiguration().getProperty("configPath"); + final String pathToFolder = Utils.getInputConfiguration().getProperty("folderPath"); + InputConfiguration inputConfiguration = new InputConfiguration(configurationPath ); + InputProgram inputProgram = InputConfiguration.initInputProgram(inputConfiguration); + inputConfiguration.setInputProgram(inputProgram); + String pathToChangedVersionOfProgram = pathToFolder + + DSpotUtils.shouldAddSeparator.apply(pathToFolder) + + (inputConfiguration.getProperty("targetModule") != null ? + inputConfiguration.getProperty("targetModule") + + DSpotUtils.shouldAddSeparator.apply(pathToFolder) + : ""); + inputProgram.setProgramDir(pathToChangedVersionOfProgram); + Initializer.initialize(Utils.getInputConfiguration(), inputProgram); + final HashMap, Failure> failurePerAmplifiedTest = new HashMap<>(); + final ChangeMinimizer changeMinimizer = new ChangeMinimizer( + testClass, + inputConfiguration, + inputProgram, + pathToChangedVersionOfProgram, + failurePerAmplifiedTest + ); + + final CtMethod test2 = Utils.findMethod(testClass, "test2"); + final CtInvocation assertion = test2.getElements(new TypeFilter(CtInvocation.class) { + @Override + public boolean matches(CtInvocation element) { + return AmplificationChecker.isAssert(element); + } + }).get(0); + final CtInvocation clone = assertion.clone(); + clone.getElements(new TypeFilter(CtLiteral.class) { + @Override + public boolean matches(CtLiteral element) { + return element.getValue() instanceof Integer && super.matches(element); + } + }).get(0).setValue(-1); + test2.getBody().insertEnd(clone); + + assertEquals(3, test2.getBody().getStatements().size()); + final CtMethod minimize = changeMinimizer.minimize(test2); + assertEquals(2, minimize.getBody().getStatements().size()); + } +} diff --git a/dspot/src/test/java/fr/inria/stamp/test/launcher/TestLauncherTest.java b/dspot/src/test/java/fr/inria/stamp/test/launcher/TestLauncherTest.java index 0ea792d71..c17adc77a 100644 --- a/dspot/src/test/java/fr/inria/stamp/test/launcher/TestLauncherTest.java +++ b/dspot/src/test/java/fr/inria/stamp/test/launcher/TestLauncherTest.java @@ -40,7 +40,6 @@ public void testOnJMockit() throws Exception { } - Utils.reset(); Utils.init("src/test/resources/jmockit/mock.properties"); final String classpath = Utils.getBuilder().buildClasspath(Utils.getInputProgram().getProgramDir()) @@ -70,7 +69,6 @@ public void testOnEasyMock() throws Exception { } - Utils.reset(); Utils.init("src/test/resources/easymock/mock.properties"); final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()) .buildClasspath(Utils.getInputProgram().getProgramDir()) @@ -100,7 +98,6 @@ public void testOnMockito() throws Exception { } - Utils.reset(); Utils.init("src/test/resources/mockito/mockito.properties"); final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()) .buildClasspath(Utils.getInputProgram().getProgramDir()) @@ -130,7 +127,6 @@ public void testOnMockito2() throws Exception { } - Utils.reset(); Utils.init("src/test/resources/mockito2/mock.properties"); final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()) .buildClasspath(Utils.getInputProgram().getProgramDir())