Skip to content

Commit

Permalink
205: test with several saved launch configurations
Browse files Browse the repository at this point in the history
Task-Url: #205
  • Loading branch information
LorenzoBettini committed Aug 25, 2022
1 parent 74381e7 commit ae4e464
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,13 @@ private Optional<ILaunchConfiguration> findExistingLaunchConfiguration(ILaunchCo
return Optional.empty();
} else if (candidateCount == 1) {
return Optional.ofNullable(candidateConfigs.get(0));
} else {
// Prompt the user to choose a config. A null result means the user
// cancelled the dialog, in which case this method returns null,
// since cancelling the dialog should also cancel launching
// anything.
ILaunchConfiguration config = chooseConfiguration(candidateConfigs);
if (config != null) {
return Optional.ofNullable(config);
}
}
return Optional.empty();

// Prompt the user to choose a config.
// if the user does not presses OK we have already interrupted
// the launch with an InterruptedException
ILaunchConfiguration config = chooseConfiguration(candidateConfigs);
return Optional.ofNullable(config);
}

private List<ILaunchConfiguration> findExistingLaunchConfigurations(ILaunchConfigurationWorkingCopy temporary) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void assertAppears() {
bot.label("No tests found");
bot.button("OK").click();

// Ensure the project is fully created before moving on
bot.waitUntil(Conditions.shellCloses(shell));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright 2022 Lorenzo Bettini and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/

package org.pitest.pitclipse.ui.behaviours.pageobjects;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;

public class TestConfigurationSelectorDialog {

private final SWTWorkbenchBot bot;
private SWTBotShell shell;

public TestConfigurationSelectorDialog(SWTWorkbenchBot bot) {
this.bot = bot;
shell = bot.shell("Select a Test Configuration");
shell.activate();
}

public void cancel() {
bot.button("Cancel").click();
bot.waitUntil(Conditions.shellCloses(shell));
}

public void choose(String option) {
bot.table().select(option);
bot.button("OK").click();
bot.waitUntil(Conditions.shellCloses(shell));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ public void runTest(final String testClassName, final String packageName, final
runPitAndWaitForIt(new SelectTestClass(testClassName, packageName, projectName));
}

public void runTest(final String testClassName, final String packageName, final String projectName,
Runnable after)
throws CoreException {
// No need to do a full build: we should be now synchronized with building
// Build the whole workspace to prevent random compilation failures
// ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD,
// new NullProgressMonitor());
System.out.println(String.format("Run PIT on: %s %s.%s", projectName, packageName, testClassName));
runPitAndWaitForIt(
new SelectTestClass(testClassName, packageName, projectName),
after);
}

public void runTestMethod(String testMethodName, final String testClassName, final String packageName, final String projectName)
throws CoreException {
// No need to do a full build: we should be now synchronized with building
Expand Down Expand Up @@ -171,15 +184,26 @@ public void runtimeOptionsMatch(Map<String, String> configMap) {
* @param runnable which is executed prior to pit
*/
public void runPitAndWaitForIt(Runnable runnable) {
runPitAndWaitForIt(runnable, () -> {});
}

/**
* Runs pit after the given runnable is run and waits for it to finish.
* @param runnable which is executed prior to pit
* @param after which is executed after pit is selected to run (e.g.,
* to select an entry in the test selection dialog)
*/
public void runPitAndWaitForIt(Runnable runnable, Runnable after) {
assertNoErrorsInWorkspace();
// reset Summary result
PitSummary.INSTANCE.resetSummary();
runnable.run();
PAGES.getRunMenu().runPit();
after.run();
// wait for pit to finish
PitSummary.INSTANCE.waitForPitToFinish();
}

public void assertNoErrorsInWorkspace() {
Set<String> errors = errorsInWorkspace();
assertThat(errors, empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ protected static void runTest(final String testClassName, final String packageNa
new PitclipseSteps().runTest(testClassName, packageName, projectName);
}

protected static void runTest(final String testClassName, final String packageName, final String projectName,
Runnable after) throws CoreException {
new PitclipseSteps().runTest(testClassName, packageName, projectName, after);
}

protected static void runSingleMethodTest(String testMethodName, final String testClassName, final String packageName, final String projectName) throws CoreException {
new PitclipseSteps().runTestMethod(testMethodName, testClassName, packageName, projectName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.pitest.pitclipse.ui.tests;

import static org.junit.Assert.assertThrows;
import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES;

import java.util.Collections;
Expand All @@ -10,6 +11,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.pitest.pitclipse.ui.behaviours.pageobjects.NoTestsFoundDialog;
import org.pitest.pitclipse.ui.behaviours.pageobjects.TestConfigurationSelectorDialog;

/**
* @author Lorenzo Bettini
Expand All @@ -24,6 +26,7 @@ public class PitclipseUiRunnerTest extends AbstractPitclipseSWTBotTest {
private static final String FOO_BAR_PACKAGE = "foo.bar";
private static final String FOO_CLASS = "Foo";
private static final String FOO_TEST_CLASS = "FooTest";
private static final String FOO_TEST_CLASS_MULTIPLE_LAUNCHES = "FooTestWithSavedConfigurations";

@BeforeClass
public static void setupJavaProject() throws CoreException {
Expand Down Expand Up @@ -195,4 +198,42 @@ public void runBinaryTest() throws CoreException {
mutationsAre(Collections.emptyList());
noCoverageReportGenerated();
}

@Test
public void multipleLaunchConfigurations() throws CoreException {
createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT,
"public int doFoo(int i) {\n"
+ " return i + 1;\n"
+ "}");
runTest(FOO_TEST_CLASS_MULTIPLE_LAUNCHES, FOO_BAR_PACKAGE, TEST_PROJECT,
() ->
new TestConfigurationSelectorDialog(bot)
.choose(FOO_TEST_CLASS_MULTIPLE_LAUNCHES));
coverageReportGenerated(1, 0, 0, 2, 0);
runTest(FOO_TEST_CLASS_MULTIPLE_LAUNCHES, FOO_BAR_PACKAGE, TEST_PROJECT,
() ->
new TestConfigurationSelectorDialog(bot)
.choose(FOO_TEST_CLASS_MULTIPLE_LAUNCHES + " (All Mutators)"));
// not just 2 mutants, but much more since in this launch
// we enabled All Mutators
coverageReportGenerated(1, 0, 0, 20, 0);

@SuppressWarnings("serial")
class MyException extends RuntimeException {

}

// cancel the launch
// we also have to interrupt with an exception, otherwise it waits
// for PIT to terminate
assertThrows(MyException.class, () ->
runTest(FOO_TEST_CLASS_MULTIPLE_LAUNCHES, FOO_BAR_PACKAGE, TEST_PROJECT,
() ->
{
new TestConfigurationSelectorDialog(bot)
.cancel();
throw new MyException();
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.pitest.pitclipse.launch.mutationTest">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.pitest.pitclipse.testprojects.emptyclasses/src/foo/bar/FooTestWithSavedConfigurations.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="foo.bar.FooTestWithSavedConfigurations"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.pitest.pitclipse.testprojects.emptyclasses"/>
<stringAttribute key="org.pitest.pitclipse.core.target.classes" value=""/>
<stringAttribute key="org.pitest.pitclipse.core.test.avoidCallsTo" value="java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j"/>
<stringAttribute key="org.pitest.pitclipse.core.test.container" value=""/>
<stringAttribute key="org.pitest.pitclipse.core.test.excludeClasses" value="*Test"/>
<stringAttribute key="org.pitest.pitclipse.core.test.excludeMethods" value=""/>
<booleanAttribute key="org.pitest.pitclipse.core.test.incrementalAnalysis" value="false"/>
<booleanAttribute key="org.pitest.pitclipse.core.test.parallel" value="true"/>
<stringAttribute key="pitIndividualMutators" value="INVERT_NEGS,MATH,VOID_METHOD_CALLS,NEGATE_CONDITIONALS,CONDITIONALS_BOUNDARY,INCREMENTS,TRUE_RETURNS,FALSE_RETURNS,PRIMITIVE_RETURNS,EMPTY_RETURNS,NULL_RETURNS"/>
<stringAttribute key="pitMutators" value="ALL"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.pitest.pitclipse.launch.mutationTest">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.pitest.pitclipse.testprojects.emptyclasses/src/foo/bar/FooTestWithSavedConfigurations.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="foo.bar.FooTestWithSavedConfigurations"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.pitest.pitclipse.testprojects.emptyclasses"/>
<stringAttribute key="org.pitest.pitclipse.core.target.classes" value=""/>
<stringAttribute key="org.pitest.pitclipse.core.test.avoidCallsTo" value="java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j"/>
<stringAttribute key="org.pitest.pitclipse.core.test.container" value=""/>
<stringAttribute key="org.pitest.pitclipse.core.test.excludeClasses" value="*Test"/>
<stringAttribute key="org.pitest.pitclipse.core.test.excludeMethods" value=""/>
<booleanAttribute key="org.pitest.pitclipse.core.test.incrementalAnalysis" value="false"/>
<booleanAttribute key="org.pitest.pitclipse.core.test.parallel" value="true"/>
<stringAttribute key="pitIndividualMutators" value="INVERT_NEGS,MATH,VOID_METHOD_CALLS,NEGATE_CONDITIONALS,CONDITIONALS_BOUNDARY,INCREMENTS,TRUE_RETURNS,FALSE_RETURNS,PRIMITIVE_RETURNS,EMPTY_RETURNS,NULL_RETURNS"/>
<stringAttribute key="pitMutators" value="DEFAULTS"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package foo.bar;

public class FooTestWithSavedConfigurations {

}

0 comments on commit ae4e464

Please sign in to comment.