From 48dc291c4b6053bdaaabe4945c2b5be63c172928 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 11:13:49 +0200 Subject: [PATCH 01/82] 81: Removed Cucumber features and test Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitclipse/ui => old-cucumber}/BundleResourceClassLoader.java | 0 .../pitest/pitclipse/ui => old-cucumber}/OsgiCucumberRunner.java | 0 .../pitclipse/ui => old-cucumber}/PitclipseFeaturesTest.java | 0 .../pitclipse/ui => old-cucumber}/j00_default_options.feature | 0 .../pitclipse/ui => old-cucumber}/j01_simple_project.feature | 0 .../ui => old-cucumber}/j02_tests_in_different_packages.feature | 0 .../ui => old-cucumber}/j03_refactored_tests_can_be_run.feature | 0 .../j04_multiple projects_in_workspace.feature | 0 .../j05_default_preferences_apply_to_launch_configuration.feature | 0 .../pitclipse/ui => old-cucumber}/j06_mutations_view.feature | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/BundleResourceClassLoader.java (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/OsgiCucumberRunner.java (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/PitclipseFeaturesTest.java (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j00_default_options.feature (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j01_simple_project.feature (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j02_tests_in_different_packages.feature (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j03_refactored_tests_can_be_run.feature (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j04_multiple projects_in_workspace.feature (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j05_default_preferences_apply_to_launch_configuration.feature (100%) rename tests/org.pitest.pitclipse.ui.tests/{src/org/pitest/pitclipse/ui => old-cucumber}/j06_mutations_view.feature (100%) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/BundleResourceClassLoader.java b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/BundleResourceClassLoader.java similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/BundleResourceClassLoader.java rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/BundleResourceClassLoader.java diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/OsgiCucumberRunner.java b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/OsgiCucumberRunner.java similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/OsgiCucumberRunner.java rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/OsgiCucumberRunner.java diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/PitclipseFeaturesTest.java b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/PitclipseFeaturesTest.java similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/PitclipseFeaturesTest.java rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/PitclipseFeaturesTest.java diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j00_default_options.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j00_default_options.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j00_default_options.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j00_default_options.feature diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j01_simple_project.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j01_simple_project.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j01_simple_project.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j01_simple_project.feature diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j02_tests_in_different_packages.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j02_tests_in_different_packages.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j02_tests_in_different_packages.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j02_tests_in_different_packages.feature diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j03_refactored_tests_can_be_run.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j03_refactored_tests_can_be_run.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j03_refactored_tests_can_be_run.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j03_refactored_tests_can_be_run.feature diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j04_multiple projects_in_workspace.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j04_multiple projects_in_workspace.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j04_multiple projects_in_workspace.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j04_multiple projects_in_workspace.feature diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j05_default_preferences_apply_to_launch_configuration.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j05_default_preferences_apply_to_launch_configuration.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j05_default_preferences_apply_to_launch_configuration.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j05_default_preferences_apply_to_launch_configuration.feature diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j06_mutations_view.feature b/tests/org.pitest.pitclipse.ui.tests/old-cucumber/j06_mutations_view.feature similarity index 100% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/j06_mutations_view.feature rename to tests/org.pitest.pitclipse.ui.tests/old-cucumber/j06_mutations_view.feature From fae3c1fd080f54d8dd18bd028ef7c619ce280e1c Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 11:14:00 +0200 Subject: [PATCH 02/82] 81: First test with SWTBot Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../org.pitest.pitclipse.ui.tests/.gitignore | 1 + .../ui/tests/AbstractPitclipseSWTBotTest.java | 113 ++++++++++++++++++ .../pitest/pitclipse/ui/tests/SimpleTest.java | 20 ++++ 3 files changed, 134 insertions(+) create mode 100644 tests/org.pitest.pitclipse.ui.tests/.gitignore create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java diff --git a/tests/org.pitest.pitclipse.ui.tests/.gitignore b/tests/org.pitest.pitclipse.ui.tests/.gitignore new file mode 100644 index 00000000..b19ec16d --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/.gitignore @@ -0,0 +1 @@ +/screenshots/ diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java new file mode 100644 index 00000000..433a4d95 --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright 2021 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.tests; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; + +import java.io.File; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.intro.IIntroManager; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.pitest.pitclipse.core.PitCoreActivator; + +/** + * @author Lorenzo Bettini + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public abstract class AbstractPitclipseSWTBotTest { + protected static SWTWorkbenchBot bot; + + @BeforeClass + public static void beforeClass() throws Exception { + bot = new SWTWorkbenchBot(); + + closeWelcomePage(); + openJavaPerspective(); + } + + @AfterClass + public static void afterClass() { + deleteAllProjects(); + bot.resetWorkbench(); + } + + protected static void closeWelcomePage() throws InterruptedException { + Display.getDefault().syncExec(new Runnable() { + public void run() { + IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager(); + if (introManager.getIntro() != null) { + introManager + .closeIntro(introManager.getIntro()); + } + } + }); + } + + protected static void openJavaPerspective() throws InterruptedException { + Display.getDefault().syncExec(new Runnable() { + public void run() { + IWorkbench workbench = PlatformUI.getWorkbench(); + try { + workbench.showPerspective("org.eclipse.jdt.ui.JavaPerspective", + workbench.getActiveWorkbenchWindow()); + } catch (WorkbenchException e) { + e.printStackTrace(); + } + } + }); + } + + protected static void createJavaProject(String projectName) { + PAGES.getFileMenu().newJavaProject(projectName); + PAGES.getAbstractSyntaxTree().addJUnitToClassPath(projectName); + } + + protected static void verifyProjectExists(String projectName) { + for (String project : PAGES.getPackageExplorer().getProjectsInWorkspace()) { + if (projectName.equals(project)) { + // Project does indeed exist + return; + } + } + fail("Project: " + projectName + " not found."); + } + + protected static void deleteAllProjects() { + for (String project : PAGES.getPackageExplorer().getProjectsInWorkspace()) { + PAGES.getAbstractSyntaxTree().deleteProject(project); + } + File historyFile = PitCoreActivator.getDefault().getHistoryFile(); + if (historyFile.exists()) { + assertTrue(historyFile.delete()); + } + } + + protected static void addToBuildPath(String dependentProject, String projectName) { + PAGES.getPackageExplorer().selectProject(projectName); + PAGES.getAbstractSyntaxTree().addProjectToClassPathOfProject(projectName, dependentProject); + } +} diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java new file mode 100644 index 00000000..8f4bc9fb --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java @@ -0,0 +1,20 @@ +package org.pitest.pitclipse.ui.tests; + +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author Lorenzo Bettini + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class SimpleTest extends AbstractPitclipseSWTBotTest { + + @Test + public void aTest() { + createJavaProject("aProject"); + verifyProjectExists("aProject"); + } + +} From b0031252804eec8448a0e06634a1b545bb559543 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 11:16:41 +0200 Subject: [PATCH 03/82] 81: re-enabled UI tests Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 4 +++- .github/workflows/windows-mac.yml | 4 +++- tests/org.pitest.pitclipse.tests.coverage.report/pom.xml | 3 --- tests/pom.xml | 3 +-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c1078729..8072bdb3 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -45,4 +45,6 @@ jobs: if: ${{ failure() }} with: name: test-results-${{ runner.os }} - path: '**/*.tests/target' + path: | + '**/*.tests/target' + '**/screenshots' diff --git a/.github/workflows/windows-mac.yml b/.github/workflows/windows-mac.yml index c1e94753..acd08962 100644 --- a/.github/workflows/windows-mac.yml +++ b/.github/workflows/windows-mac.yml @@ -42,4 +42,6 @@ jobs: if: ${{ failure() }} with: name: test-results-${{ runner.os }} - path: '**/*.tests/target' + path: | + '**/*.tests/target' + '**/screenshots' diff --git a/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml b/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml index 0af988b3..e81e0f43 100644 --- a/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml +++ b/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml @@ -58,14 +58,11 @@ ${project.version} compile - - diff --git a/tests/pom.xml b/tests/pom.xml index 8af5e499..1ed15bfb 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -21,8 +21,7 @@ org.pitest.pitclipse.runner.tests - - + org.pitest.pitclipse.ui.tests io.cucumber From e8aa29a13fd190d5972a8e7915f9760202abf280 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 11:27:07 +0200 Subject: [PATCH 04/82] 81: update upload artifacts Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 2 +- .github/workflows/windows-mac.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8072bdb3..74f173a1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -47,4 +47,4 @@ jobs: name: test-results-${{ runner.os }} path: | '**/*.tests/target' - '**/screenshots' + '**/*.tests/screenshots' diff --git a/.github/workflows/windows-mac.yml b/.github/workflows/windows-mac.yml index acd08962..d909bd2d 100644 --- a/.github/workflows/windows-mac.yml +++ b/.github/workflows/windows-mac.yml @@ -44,4 +44,4 @@ jobs: name: test-results-${{ runner.os }} path: | '**/*.tests/target' - '**/screenshots' + '**/*.tests/screenshots' From 7978763427c310242f94644e7e47f6fc4f630bb9 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 11:31:15 +0200 Subject: [PATCH 05/82] 81: update upload artifacts Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 10 +++++++--- .github/workflows/windows-mac.yml | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 74f173a1..5c0a874f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -45,6 +45,10 @@ jobs: if: ${{ failure() }} with: name: test-results-${{ runner.os }} - path: | - '**/*.tests/target' - '**/*.tests/screenshots' + path: '**/*.tests/target' + - name: Archive UI Tests Screenshots + uses: actions/upload-artifact@v2 + if: ${{ failure() }} + with: + name: screenshots-${{ runner.os }} + path: '**/*.tests/screenshots' diff --git a/.github/workflows/windows-mac.yml b/.github/workflows/windows-mac.yml index d909bd2d..d3b12258 100644 --- a/.github/workflows/windows-mac.yml +++ b/.github/workflows/windows-mac.yml @@ -42,6 +42,10 @@ jobs: if: ${{ failure() }} with: name: test-results-${{ runner.os }} - path: | - '**/*.tests/target' - '**/*.tests/screenshots' + path: '**/*.tests/target' + - name: Archive UI Tests Screenshots + uses: actions/upload-artifact@v2 + if: ${{ failure() }} + with: + name: screenshots-${{ runner.os }} + path: '**/*.tests/screenshots' From 38281ca608b7d155275f9e2b8ee6cc516e5d6827 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 12:33:21 +0200 Subject: [PATCH 06/82] 81: switch to Photon Oxygen gives problem when running UI tests with Java 11: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../org.pitest.pitclipse.target.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target b/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target index 1aa82ee0..c83aa95d 100644 --- a/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target +++ b/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target @@ -10,7 +10,7 @@ - + From a29af7379c79619dfdfe727c6e13e03c6667db3d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 12:33:54 +0200 Subject: [PATCH 07/82] 81: Make sure to select JavaSE-1.8 for Java project Otherwise we get another disturbing dialog for module-info.java when running with Java 11 Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/behaviours/pageobjects/NewProjectWizard.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NewProjectWizard.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NewProjectWizard.java index 8d032c63..0995f6bc 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NewProjectWizard.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NewProjectWizard.java @@ -34,8 +34,11 @@ public void createJavaProject(String projectName) { bot.tree().expandNode("Java").select("Java Project"); bot.button("Next >").click(); bot.textWithLabel("Project name:").setText(projectName); + // make sure to set Java 8 otherwise we get another dialog for module-info.java + bot.radio("Use an execution environment JRE:").click(); + bot.comboBox().setSelection("JavaSE-1.8"); bot.button("Finish").click(); - + // Ensure the project is fully created before moving on bot.waitUntil(Conditions.shellCloses(shell)); } From 9b0bec776eb4007cf1ec22cc5d5e2b03ad563cb1 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 12:34:31 +0200 Subject: [PATCH 08/82] 81: refactored argLine for UI tests to include module arguments for Java 11 and for macOS UI tests Task-Url: http://github.com/pitest/pitclipse/issues/81 --- tests/org.pitest.pitclipse.ui.tests/pom.xml | 85 +++++++++++++++------ 1 file changed, 61 insertions(+), 24 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/pom.xml b/tests/org.pitest.pitclipse.ui.tests/pom.xml index cabb8c25..6d8421e9 100644 --- a/tests/org.pitest.pitclipse.ui.tests/pom.xml +++ b/tests/org.pitest.pitclipse.ui.tests/pom.xml @@ -1,9 +1,10 @@ - 4.0.0 - org.pitest - org.pitest.pitclipse.ui.tests - eclipse-test-plugin + org.pitest + org.pitest.pitclipse.ui.tests + eclipse-test-plugin org.pitest @@ -11,27 +12,63 @@ 2.1.2-SNAPSHOT + + + + + + + ${moduleProperties} + + + + + jdk9-or-newer + + [9,) + + + --add-modules=ALL-SYSTEM + + + + macosx-jvm-flags + + + mac + + + + -XstartOnFirstThread + + + + jacoco + + false + + + ${tycho.testArgLine} ${moduleProperties} + + + + - - - - org.eclipse.tycho - tycho-surefire-plugin - ${tycho-version} - - true - false - org.eclipse.platform.ide - org.eclipse.ui.ide.workbench - true - - - + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + true + false + true + ${additionalTestArgLine} ${os-jvm-flags} + + + org.eclipse.tycho target-platform-configuration From 8799af100555f4180b1725a5e0be4bb42611784b Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 12:37:37 +0200 Subject: [PATCH 09/82] 81: Temporarily enable Windows and macOS always Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/windows-mac.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/windows-mac.yml b/.github/workflows/windows-mac.yml index d3b12258..8d586b47 100644 --- a/.github/workflows/windows-mac.yml +++ b/.github/workflows/windows-mac.yml @@ -7,10 +7,6 @@ on: push: paths-ignore: - 'README.md' - # Sequence of patterns matched against refs/heads - branches: - # Push events on the main branch - - master pull_request: paths-ignore: - 'README.md' From 4eb1110547e554333b43e211f0ac451c8f5d89ee Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 15:54:57 +0200 Subject: [PATCH 10/82] 81: try to run PIT in UI test Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 15 +++++++++++++++ .../pitest/pitclipse/ui/tests/SimpleTest.java | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 433a4d95..cebcbdc3 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -21,6 +21,7 @@ import java.io.File; +import org.eclipse.core.runtime.CoreException; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; @@ -32,6 +33,7 @@ import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; /** * @author Lorenzo Bettini @@ -110,4 +112,17 @@ protected static void addToBuildPath(String dependentProject, String projectName PAGES.getPackageExplorer().selectProject(projectName); PAGES.getAbstractSyntaxTree().addProjectToClassPathOfProject(projectName, dependentProject); } + + protected static void createClass(String className, String packageName, String projectName) { + PAGES.getBuildProgress().listenForBuild(); + PAGES.getPackageExplorer().selectPackageRoot(projectName, "src"); + // Cannot use the Package explorer right click context menu + // to create a class due to SWTBot bug 261360 + PAGES.getFileMenu().createClass(packageName, className); + PAGES.getBuildProgress().waitForBuild(); + } + + protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { + new PitclipseSteps().runTest(testClassName, packageName, projectName); + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java index 8f4bc9fb..d9baf0f0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java @@ -1,6 +1,8 @@ package org.pitest.pitclipse.ui.tests; +import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -11,10 +13,19 @@ @RunWith(SWTBotJunit4ClassRunner.class) public class SimpleTest extends AbstractPitclipseSWTBotTest { + private static final String TEST_PROJECT = "project1"; + + @BeforeClass + public static void setupJavaProject() { + createJavaProject(TEST_PROJECT); + verifyProjectExists(TEST_PROJECT); + } + @Test - public void aTest() { - createJavaProject("aProject"); - verifyProjectExists("aProject"); + public void aTest() throws CoreException { + createClass("Foo", "foo.bar", TEST_PROJECT); + createClass("FooTest", "foo.bar", TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); } } From 9c2780a5695581737098cda5714224bc0f38ea9b Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 17:10:46 +0200 Subject: [PATCH 11/82] 81: org.eclipse.jdt to UI tests TP Task-Url: http://github.com/pitest/pitclipse/issues/81 --- tests/org.pitest.pitclipse.ui.tests/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/pom.xml b/tests/org.pitest.pitclipse.ui.tests/pom.xml index 6d8421e9..13061703 100644 --- a/tests/org.pitest.pitclipse.ui.tests/pom.xml +++ b/tests/org.pitest.pitclipse.ui.tests/pom.xml @@ -81,6 +81,12 @@ org.pitest.pitclipse.listeners 0.0.0 + + + eclipse-feature + org.eclipse.jdt + 0.0.0 + From e84fb7734d8aa90b44856afac49f93d92bf6b6d5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 17:31:07 +0200 Subject: [PATCH 12/82] 81: install libwebkit2gtk in Linux Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5c0a874f..79043488 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,6 +23,10 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 + - name: Install WebKit + run: | + sudo apt update + sudo apt install -y libwebkit2gtk - name: Cache Maven packages uses: actions/cache@v2 with: From 1d66e118419553445a9a62a59faea74c3e7defe6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 17:33:26 +0200 Subject: [PATCH 13/82] 81: install libwebkit2gtk-4.0-37 Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 79043488..ab9c4183 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,7 +26,7 @@ jobs: - name: Install WebKit run: | sudo apt update - sudo apt install -y libwebkit2gtk + sudo apt install -y libwebkit2gtk-4.0-37 - name: Cache Maven packages uses: actions/cache@v2 with: From 5927850f058d01d75a89a7fc9b224b4f6c518505 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 17:39:18 +0200 Subject: [PATCH 14/82] 81: document libwebkit in Linux Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ab9c4183..08d53b09 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,7 +23,7 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - name: Install WebKit + - name: Install WebKit # required for SWT Browser run: | sudo apt update sudo apt install -y libwebkit2gtk-4.0-37 From 1603bec9671679b72624016d2c426a4cb90fb44f Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 17:41:11 +0200 Subject: [PATCH 15/82] 81: refactored TP configuration in UI tests Task-Url: http://github.com/pitest/pitclipse/issues/81 --- tests/org.pitest.pitclipse.ui.tests/pom.xml | 30 ++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/pom.xml b/tests/org.pitest.pitclipse.ui.tests/pom.xml index 13061703..404efc0c 100644 --- a/tests/org.pitest.pitclipse.ui.tests/pom.xml +++ b/tests/org.pitest.pitclipse.ui.tests/pom.xml @@ -41,6 +41,28 @@ -XstartOnFirstThread + + + + org.eclipse.tycho + target-platform-configuration + + + + + + eclipse-feature + org.eclipse.jdt + 0.0.0 + + + + + + + jacoco @@ -75,18 +97,12 @@ ${tycho-version} - + eclipse-plugin org.pitest.pitclipse.listeners 0.0.0 - - - eclipse-feature - org.eclipse.jdt - 0.0.0 - From 56ac4c3e8c356dcca8a9a76e9778e26b99f2fbdd Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 18:14:12 +0200 Subject: [PATCH 16/82] 85: verify Console text Task-Url: http://github.com/pitest/pitclipse/issues/85 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 19 +++++++++++++++++++ .../pitest/pitclipse/ui/tests/SimpleTest.java | 1 + 2 files changed, 20 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index cebcbdc3..2552f71d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -15,6 +15,8 @@ ******************************************************************************/ package org.pitest.pitclipse.ui.tests; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; @@ -24,6 +26,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; @@ -125,4 +128,20 @@ protected static void createClass(String className, String packageName, String p protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { new PitclipseSteps().runTest(testClassName, packageName, projectName); } + + protected static void consoleContains(int generatedMutants, int testsRun) { + SWTBotView consoleView = bot.viewByPartName("Console"); + consoleView.show(); + String consoleText = consoleView.bot() + .styledText().getText() + .replace("\r", ""); + assertThat(consoleText, + containsString( + String.format( + ">> Generated %d mutations Killed 0 (100%%)\n" + + ">> Ran %d tests (0 tests per mutation)", + generatedMutants, testsRun) + ) + ); + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java index d9baf0f0..0d69516e 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java @@ -26,6 +26,7 @@ public void aTest() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); createClass("FooTest", "foo.bar", TEST_PROJECT); runTest("FooTest", "foo.bar", TEST_PROJECT); + consoleContains(0, 0); } } From 4b1f48d3f5c312b8041b99139bc0d77786926766 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 18:26:24 +0200 Subject: [PATCH 17/82] 85: verify PIT Mutations view Task-Url: http://github.com/pitest/pitclipse/issues/85 --- .../pageobjects/PitMutationsView.java | 20 +++++++++---------- .../ui/tests/AbstractPitclipseSWTBotTest.java | 10 ++++++++++ .../pitest/pitclipse/ui/tests/SimpleTest.java | 3 +++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java index ef9fe0a1..a5297d7d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java @@ -16,10 +16,13 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; +import static org.pitest.pitclipse.ui.behaviours.pageobjects.SwtBotTreeHelper.expand; +import static org.pitest.pitclipse.ui.util.StepUtil.safeSleep; + +import java.util.List; +import java.util.concurrent.TimeoutException; +import java.util.regex.Pattern; -import junit.framework.AssertionFailedError; import org.eclipse.core.runtime.jobs.IJobManager; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; @@ -33,13 +36,10 @@ import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; import org.pitest.pitclipse.ui.view.mutations.OpenMutationDoubleClick; -import java.util.List; -import java.util.concurrent.TimeoutException; -import java.util.regex.Pattern; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; -import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; -import static org.pitest.pitclipse.ui.behaviours.pageobjects.SwtBotTreeHelper.expand; -import static org.pitest.pitclipse.ui.util.StepUtil.safeSleep; +import junit.framework.AssertionFailedError; public class PitMutationsView { @@ -51,7 +51,7 @@ public PitMutationsView(SWTWorkbenchBot bot) { public List getMutations() { safeSleep(1000); - PAGES.views().closeConsole(); +// PAGES.views().closeConsole(); SWTBotTree mutationTree = mutationTreeRoot(); return mutationsFrom(mutationTree); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 2552f71d..d43deff6 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -15,6 +15,8 @@ ******************************************************************************/ package org.pitest.pitclipse.ui.tests; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertTrue; @@ -22,6 +24,7 @@ import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; import java.io.File; +import java.util.List; import org.eclipse.core.runtime.CoreException; import org.eclipse.swt.widgets.Display; @@ -36,6 +39,7 @@ import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; /** @@ -144,4 +148,10 @@ protected static void consoleContains(int generatedMutants, int testsRun) { ) ); } + + protected static void mutationsAre(List expectedMutations) { + List actualMutations = PAGES.getPitMutationsView().getMutations(); + assertThat(actualMutations, is(equalTo(expectedMutations))); + } + } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java index 0d69516e..a57140e7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java @@ -1,5 +1,7 @@ package org.pitest.pitclipse.ui.tests; +import java.util.Collections; + import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.BeforeClass; @@ -27,6 +29,7 @@ public void aTest() throws CoreException { createClass("FooTest", "foo.bar", TEST_PROJECT); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0); + mutationsAre(Collections.emptyList()); } } From 437244bcb4e69399a7f038673070bf6522a6257c Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 18:51:18 +0200 Subject: [PATCH 18/82] 85: test with empty test method Task-Url: http://github.com/pitest/pitclipse/issues/85 --- .../pageobjects/AbstractSyntaxTree.java | 2 +- .../ui/tests/AbstractPitclipseSWTBotTest.java | 15 +++++++++++++++ .../pitest/pitclipse/ui/tests/SimpleTest.java | 19 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java index a405e1da..cf9be4d8 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java @@ -53,7 +53,7 @@ private IJavaProject getJavaProject(ClassContext context) { return getJavaProject(context.getProjectName()); } - private IJavaProject getJavaProject(String projectName) { + public IJavaProject getJavaProject(String projectName) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); return JavaCore.create(project); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index d43deff6..a8353ed7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -27,6 +27,7 @@ import java.util.List; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; @@ -39,6 +40,7 @@ import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.ui.behaviours.steps.ClassSteps; import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; @@ -115,6 +117,12 @@ protected static void deleteAllProjects() { } } + protected static void deleteSrcContents(String projectName) throws CoreException { + IJavaProject javaProject = PAGES.getAbstractSyntaxTree().getJavaProject(projectName); + javaProject.getProject().getFolder("src").delete(true, null); + javaProject.getProject().getFolder("src").create(true, true, null); + } + protected static void addToBuildPath(String dependentProject, String projectName) { PAGES.getPackageExplorer().selectProject(projectName); PAGES.getAbstractSyntaxTree().addProjectToClassPathOfProject(projectName, dependentProject); @@ -129,6 +137,13 @@ protected static void createClass(String className, String packageName, String p PAGES.getBuildProgress().waitForBuild(); } + protected static void createMethod(String className, String packageName, String projectName, + String method) { + ClassSteps classSteps = new ClassSteps(); + classSteps.selectClass(className, packageName, projectName); + classSteps.createMethod(method); + } + protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { new PitclipseSteps().runTest(testClassName, packageName, projectName); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java index a57140e7..7812a131 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java @@ -4,6 +4,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -23,10 +24,26 @@ public static void setupJavaProject() { verifyProjectExists(TEST_PROJECT); } + @Before + public void cleanProject() throws CoreException { + deleteSrcContents(TEST_PROJECT); + } + + @Test + public void emptyClassAndEmptyTest() throws CoreException { + createClass("Foo", "foo.bar", TEST_PROJECT); + createClass("FooTest", "foo.bar", TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); + consoleContains(0, 0); + mutationsAre(Collections.emptyList()); + } + @Test - public void aTest() throws CoreException { + public void emptyClassAndEmptyTestMethod() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); createClass("FooTest", "foo.bar", TEST_PROJECT); + createMethod("FooTest", "foo.bar", TEST_PROJECT, + "@Test public void fooTest1() {Foo foo = new Foo();}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0); mutationsAre(Collections.emptyList()); From ad6bfc62484d113da3033e37bcaa0c8501800215 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 19:07:32 +0200 Subject: [PATCH 19/82] 85: wait for build when deleting src contents Task-Url: http://github.com/pitest/pitclipse/issues/85 --- .../pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index a8353ed7..4597033e 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -118,9 +118,11 @@ protected static void deleteAllProjects() { } protected static void deleteSrcContents(String projectName) throws CoreException { + PAGES.getBuildProgress().listenForBuild(); IJavaProject javaProject = PAGES.getAbstractSyntaxTree().getJavaProject(projectName); javaProject.getProject().getFolder("src").delete(true, null); javaProject.getProject().getFolder("src").create(true, true, null); + PAGES.getBuildProgress().waitForBuild(); } protected static void addToBuildPath(String dependentProject, String projectName) { From a7159f817dca15e2e2546c79be7fc11db3899bab Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sun, 9 May 2021 19:55:27 +0200 Subject: [PATCH 20/82] 81: test with bad test Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 33 ++++++++++++++++--- .../pitest/pitclipse/ui/tests/SimpleTest.java | 17 ++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 4597033e..0841362c 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -31,7 +31,9 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.SWTBot; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.waits.ICondition; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; @@ -150,18 +152,41 @@ protected static void runTest(final String testClassName, final String packageNa new PitclipseSteps().runTest(testClassName, packageName, projectName); } - protected static void consoleContains(int generatedMutants, int testsRun) { + protected static void consoleContains(int generatedMutants, int killedMutants, + int killedPercentage, + int testsRun, + int testsPerMutations) { SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.show(); + bot.waitUntil(new ICondition() { + @Override + public boolean test() { + return consoleView.bot() + .styledText().getText() + .trim() + .endsWith("tests per mutation)"); + } + + @Override + public void init(SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Console View is empty"; + } + }); String consoleText = consoleView.bot() .styledText().getText() .replace("\r", ""); + System.out.println(consoleText); assertThat(consoleText, containsString( String.format( - ">> Generated %d mutations Killed 0 (100%%)\n" - + ">> Ran %d tests (0 tests per mutation)", - generatedMutants, testsRun) + ">> Generated %d mutations Killed %d (%d%%)\n" + + ">> Ran %d tests (%d tests per mutation)", + generatedMutants, killedMutants, + killedPercentage, testsRun, testsPerMutations) ) ); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java index 7812a131..ea8c6493 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java @@ -34,7 +34,7 @@ public void emptyClassAndEmptyTest() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); createClass("FooTest", "foo.bar", TEST_PROJECT); runTest("FooTest", "foo.bar", TEST_PROJECT); - consoleContains(0, 0); + consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); } @@ -45,8 +45,21 @@ public void emptyClassAndEmptyTestMethod() throws CoreException { createMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); runTest("FooTest", "foo.bar", TEST_PROJECT); - consoleContains(0, 0); + consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); } + @Test + public void classWithMethodAndBadTestMethod() throws CoreException { + createClass("Foo", "foo.bar", TEST_PROJECT); + createMethod("Foo", "foo.bar", TEST_PROJECT, + "public int doFoo(int i) {return i + 1;}"); + createClass("FooTest", "foo.bar", TEST_PROJECT); + createMethod("FooTest", "foo.bar", TEST_PROJECT, + "@Test public void fooTest1() {Foo foo = new Foo();}"); + runTest("FooTest", "foo.bar", TEST_PROJECT); + consoleContains(2, 0, 0, 0, 0); +// mutationsAre(Collections.emptyList()); + } + } From 08b11a007cd924aa2e2e39f2675cb64f518a164b Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 10:53:12 +0200 Subject: [PATCH 21/82] 81: updated sequenceNumber in TP Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../org.pitest.pitclipse.target.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target b/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target index f4b4b756..c8cbf21c 100644 --- a/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target +++ b/releng/org.pitest.pitclipse.target/org.pitest.pitclipse.target.target @@ -1,6 +1,6 @@ - + From 73245e740f595ad0435e07cd1a3c42feff046bd2 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 13:30:03 +0200 Subject: [PATCH 22/82] 81: renamed testcase Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/{SimpleTest.java => PitclipseUiRunnerTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/{SimpleTest.java => PitclipseUiRunnerTest.java} (96%) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java similarity index 96% rename from tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java rename to tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index ea8c6493..a4428e26 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/SimpleTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -14,7 +14,7 @@ * */ @RunWith(SWTBotJunit4ClassRunner.class) -public class SimpleTest extends AbstractPitclipseSWTBotTest { +public class PitclipseUiRunnerTest extends AbstractPitclipseSWTBotTest { private static final String TEST_PROJECT = "project1"; From 0bf65571c373c5bc56679fc206f9d6ca99f74bad Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 13:35:10 +0200 Subject: [PATCH 23/82] 81: createClassWithMethod Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 6 ++++++ .../pitclipse/ui/tests/PitclipseUiRunnerTest.java | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 0841362c..d565fe36 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -132,6 +132,12 @@ protected static void addToBuildPath(String dependentProject, String projectName PAGES.getAbstractSyntaxTree().addProjectToClassPathOfProject(projectName, dependentProject); } + protected static void createClassWithMethod(String className, String packageName, String projectName, + String method) { + createClass(className, packageName, projectName); + createMethod(className, packageName, projectName, method); + } + protected static void createClass(String className, String packageName, String projectName) { PAGES.getBuildProgress().listenForBuild(); PAGES.getPackageExplorer().selectPackageRoot(projectName, "src"); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index a4428e26..a6b35712 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -41,8 +41,7 @@ public void emptyClassAndEmptyTest() throws CoreException { @Test public void emptyClassAndEmptyTestMethod() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); - createClass("FooTest", "foo.bar", TEST_PROJECT); - createMethod("FooTest", "foo.bar", TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); @@ -51,11 +50,8 @@ public void emptyClassAndEmptyTestMethod() throws CoreException { @Test public void classWithMethodAndBadTestMethod() throws CoreException { - createClass("Foo", "foo.bar", TEST_PROJECT); - createMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); - createClass("FooTest", "foo.bar", TEST_PROJECT); - createMethod("FooTest", "foo.bar", TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); From fb4c60e663f0c8bc346e4243f147446371e01b53 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 14:09:23 +0200 Subject: [PATCH 24/82] 81: clearConsole Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 12 ++++++++++-- .../pitclipse/ui/tests/PitclipseUiRunnerTest.java | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index d565fe36..7d5dc987 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -16,7 +16,6 @@ package org.pitest.pitclipse.ui.tests; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertTrue; @@ -158,6 +157,15 @@ protected static void runTest(final String testClassName, final String packageNa new PitclipseSteps().runTest(testClassName, packageName, projectName); } + /** + * To make sure we don't get output from previous test runs + */ + protected static void clearConsole() { + SWTBotView consoleView = bot.viewByPartName("Console"); + consoleView.show(); + consoleView.bot().styledText().setText(""); + } + protected static void consoleContains(int generatedMutants, int killedMutants, int killedPercentage, int testsRun, @@ -199,7 +207,7 @@ public String getFailureMessage() { protected static void mutationsAre(List expectedMutations) { List actualMutations = PAGES.getPitMutationsView().getMutations(); - assertThat(actualMutations, is(equalTo(expectedMutations))); + assertThat(actualMutations, equalTo(expectedMutations)); } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index a6b35712..413a8ce0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -4,6 +4,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -29,6 +30,11 @@ public void cleanProject() throws CoreException { deleteSrcContents(TEST_PROJECT); } + @After + public void cleanConsole() { + clearConsole(); + } + @Test public void emptyClassAndEmptyTest() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); From c9b7632ded69b24489907b4bffc00d07510249b1 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 14:12:50 +0200 Subject: [PATCH 25/82] 81: clear the console with toolbar button Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 7d5dc987..9417b043 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -163,7 +163,9 @@ protected static void runTest(final String testClassName, final String packageNa protected static void clearConsole() { SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.show(); - consoleView.bot().styledText().setText(""); + // use the toolbar button instead of .bot().styledText().setText("") + // which does not seem to work synchronously + consoleView.toolbarButton("Clear Console").click(); } protected static void consoleContains(int generatedMutants, int killedMutants, From c2c94bbc1035c42db132d7b08bc11bfa9040702c Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 14:45:29 +0200 Subject: [PATCH 26/82] 81: mutationsAre(String) Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/behaviours/steps/PitclipseSteps.java | 4 +- .../ui/tests/AbstractPitclipseSWTBotTest.java | 42 +++++++++++++++++++ .../ui/tests/PitclipseUiRunnerTest.java | 4 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index e4571ca8..4dbefcca 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -219,8 +219,9 @@ private final Set errorsInProblemsView() { } private List mutationsFromExampleTable(DataTable tableOfMutations) { + List> asMaps = tableOfMutations.asMaps(); ImmutableList.Builder projectsBuilder = ImmutableList.builder(); - for (Map mutationRow : tableOfMutations.asMaps()) { + for (Map mutationRow : asMaps) { DetectionStatus status = DetectionStatus.valueOf(mutationRow.get("status")); String project = mutationRow.get("project"); String pkg = mutationRow.get("package"); @@ -232,7 +233,6 @@ private List mutationsFromExampleTable(DataTable tableOfMutations) projectsBuilder.add(pitMutation); } return projectsBuilder.build(); - } private Matcher match(final Map optionRow) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 9417b043..8ced4215 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -15,6 +15,7 @@ ******************************************************************************/ package org.pitest.pitclipse.ui.tests; +import static java.lang.Integer.parseInt; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -23,6 +24,7 @@ import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; import java.io.File; +import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.CoreException; @@ -41,6 +43,7 @@ import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.runner.results.DetectionStatus; import org.pitest.pitclipse.ui.behaviours.steps.ClassSteps; import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; @@ -207,6 +210,45 @@ public String getFailureMessage() { ); } + /** + * The expectedMutationsTable String argument represents the expected + * mutations table, this is an example of String: + * (the headers of the table are the following ones:) + *
+     *  status      | project  | package | class       | line | mutation
+     * 
+ * + *
+     * "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction       \n" +
+     * "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "
+     * 
+ * + * @param expectedMutationsTable + */ + protected static void mutationsAre(String expectedMutationsTable) { + List expectedMutations = new ArrayList<>(); + String[] lines = expectedMutationsTable.split("\n"); + final int statusIndex = 0; + final int projectIndex = 1; + final int packageIndex = 2; + final int classIndex = 3; + final int lineIndex = 4; + final int mutationIndex = 5; + for (String string : lines) { + String[] mutationRow = string.split("\\|"); + DetectionStatus status = DetectionStatus.valueOf(mutationRow[statusIndex].trim()); + String project = mutationRow[projectIndex].trim(); + String pkg = mutationRow[packageIndex].trim(); + String className = mutationRow[classIndex].trim(); + int line = parseInt(mutationRow[lineIndex].trim()); + String mutation = mutationRow[mutationIndex].trim(); + PitMutation pitMutation = PitMutation.builder().withStatus(status).withProject(project).withPackage(pkg) + .withClassName(className).withLineNumber(line).withMutation(mutation).build(); + expectedMutations.add(pitMutation); + } + mutationsAre(expectedMutations); + } + protected static void mutationsAre(List expectedMutations) { List actualMutations = PAGES.getPitMutationsView().getMutations(); assertThat(actualMutations, equalTo(expectedMutations)); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index 413a8ce0..dcecc8d0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -61,7 +61,9 @@ public void classWithMethodAndBadTestMethod() throws CoreException { "@Test public void fooTest1() {Foo foo = new Foo();}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); -// mutationsAre(Collections.emptyList()); + mutationsAre( + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); } } From 7e9fe7d77f066851b0b9e0afac32de709cc34d62 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 15:08:19 +0200 Subject: [PATCH 27/82] 81: clearConsole doesn't fail if view is not found Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 8ced4215..f9ce50be 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -33,6 +33,7 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.waits.ICondition; import org.eclipse.ui.IWorkbench; @@ -161,11 +162,18 @@ protected static void runTest(final String testClassName, final String packageNa } /** - * To make sure we don't get output from previous test runs + * If the Console view can be found then clear it, to make sure we don't get + * output from previous test runs */ protected static void clearConsole() { - SWTBotView consoleView = bot.viewByPartName("Console"); - consoleView.show(); + SWTBotView consoleView; + try { + consoleView = bot.viewByPartName("Console"); + consoleView.show(); + } catch (WidgetNotFoundException e) { + e.printStackTrace(); + return; + } // use the toolbar button instead of .bot().styledText().setText("") // which does not seem to work synchronously consoleView.toolbarButton("Clear Console").click(); From 1d46440cfabbc862dd3f18e860b4184472f47d58 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 15:13:32 +0200 Subject: [PATCH 28/82] 81: wait for build after creating the project Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index f9ce50be..010ec5e1 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -98,8 +98,10 @@ public void run() { } protected static void createJavaProject(String projectName) { + PAGES.getBuildProgress().listenForBuild(); PAGES.getFileMenu().newJavaProject(projectName); PAGES.getAbstractSyntaxTree().addJUnitToClassPath(projectName); + PAGES.getBuildProgress().waitForBuild(); } protected static void verifyProjectExists(String projectName) { From 2d71b3eb4f2aeb22c9c14e1f77a61402d462c73d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 10 May 2021 15:15:56 +0200 Subject: [PATCH 29/82] 81: swtbot.search.timeout=20000 Task-Url: http://github.com/pitest/pitclipse/issues/81 --- tests/org.pitest.pitclipse.ui.tests/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/pom.xml b/tests/org.pitest.pitclipse.ui.tests/pom.xml index 404efc0c..2f3a1c7d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/pom.xml +++ b/tests/org.pitest.pitclipse.ui.tests/pom.xml @@ -86,7 +86,7 @@ true false true - ${additionalTestArgLine} ${os-jvm-flags} + ${additionalTestArgLine} ${os-jvm-flags} -Dorg.eclipse.swtbot.search.timeout=20000
+ + eclipse-plugin + org.eclipse.jdt.junit5.runtime + 0.0.0 + + + + eclipse-plugin + org.pitest.pitest-junit5-plugin + 0.0.0 + From 785d40c271954e3a06d025f93a1876bf815f4b8d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 12:35:47 +0200 Subject: [PATCH 39/82] 81: speed up closing "Select a Test Configuration" Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/behaviours/pageobjects/RunMenu.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index e1dcb28b..85913ca7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -19,6 +19,7 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.pitest.pitclipse.runner.PitOptions; import org.pitest.pitclipse.ui.swtbot.PitOptionsNotifier; import org.pitest.pitclipse.ui.swtbot.SWTBotMenuHelper; @@ -51,15 +52,28 @@ public void runPit() { .menu(RUN_AS); menuHelper.findMenu(runAsMenu, PIT_MUTATION_TEST) .click(); - try { - bot.shell("Select a Test Configuration") - .bot() - .button("OK") - .click(); - } catch (WidgetNotFoundException e) { - // The 'Select a Test Configuration' dialog only appears when Pit has been launched - // at least once. If it is not found then PIT has been launched directly during the - // click on 'Run As > PIT Mutation Test' so everything's alright. + + ensureSelectTestConfigurationDialogIsClosed(); + } + + /** + * The 'Select a Test Configuration' dialog only appears when Pit has been + * launched at least once. If it is not found then PIT has been launched + * directly during the click on 'Run As > PIT Mutation Test' so everything's + * alright. + * + * This is a fast way for closing the dialog by iterating over the shells, instead + * of searching for such a shell swallowing {@link WidgetNotFoundException}. + */ + private void ensureSelectTestConfigurationDialogIsClosed() { + SWTBotShell[] shells = bot.shells(); + for (SWTBotShell shell : shells) { + if ("Select a Test Configuration".equals(shell.getText())) { + shell.bot() + .button("OK") + .click(); + return; + } } } From 3a817e99d070e0a9275cfe67d6e99b8b3cb904c6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 14:22:45 +0200 Subject: [PATCH 40/82] 81: clear the console before running PIT Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/behaviours/pageobjects/RunMenu.java | 4 ++-- .../ui/behaviours/pageobjects/Views.java | 23 +++++++++++++++++-- .../ui/behaviours/steps/PitclipseSteps.java | 4 +++- .../ui/tests/AbstractPitclipseSWTBotTest.java | 21 ----------------- .../ui/tests/PitclipseUiRunnerJUnit5Test.java | 8 ------- .../ui/tests/PitclipseUiRunnerTest.java | 8 ------- 6 files changed, 26 insertions(+), 42 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index 85913ca7..a08a07d8 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -16,6 +16,8 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; +import java.util.List; + import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; @@ -24,8 +26,6 @@ import org.pitest.pitclipse.ui.swtbot.PitOptionsNotifier; import org.pitest.pitclipse.ui.swtbot.SWTBotMenuHelper; -import java.util.List; - public class RunMenu { private static final String RUN = "Run"; diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Views.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Views.java index d6feebfc..6c5fbede 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Views.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Views.java @@ -16,13 +16,13 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; +import java.util.List; + import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.SWTBot; import org.eclipse.swtbot.swt.finder.waits.ICondition; -import java.util.List; - public class Views { private final SWTWorkbenchBot bot; @@ -40,6 +40,25 @@ public void closeConsole() { } } + /** + * If the Console view can be found then clear it, to make sure we don't get + * output from previous test runs + */ + public void clearConsole() { + List allViews = bot.views(); + for (SWTBotView view : allViews) { + if ("Console".equals(view.getTitle())) { + view.show(); + if (!view.bot().styledText().getText().isEmpty()) { + // use the toolbar button instead of .bot().styledText().setText("") + // which does not seem to work synchronously + view.toolbarButton("Clear Console").click(); + } + return; + } + } + } + public void waitForTestsAreRunOnConsole() { SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.show(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index d6bfa72d..562f65b7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -140,7 +140,9 @@ public void runtimeOptionsMatch(DataTable configTable) { private void runPit(Runnable runnable) { assertPitCanRun(); - + // make sure to clear the console to avoid interferences + // with the output of previous runs + PAGES.views().clearConsole(); int retryCount = 20; int counter = 0; while (counter < retryCount) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 8fe0fd44..2aeef9eb 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -32,7 +32,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; @@ -192,26 +191,6 @@ protected static void runProjectTest(final String projectName) throws CoreExcept new PitclipseSteps().runProjectTest(projectName); } - /** - * If the Console view can be found then clear it, to make sure we don't get - * output from previous test runs - */ - protected static void clearConsole() { - SWTBotView consoleView; - try { - consoleView = bot.viewByPartName("Console"); - consoleView.show(); - } catch (WidgetNotFoundException e) { - e.printStackTrace(); - return; - } - if (consoleView.bot().styledText().getText().isEmpty()) - return; - // use the toolbar button instead of .bot().styledText().setText("") - // which does not seem to work synchronously - consoleView.toolbarButton("Clear Console").click(); - } - protected static void consoleContains(int generatedMutants, int killedMutants, int killedPercentage, int testsRun, diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java index 65eea68d..a73235f8 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java @@ -2,7 +2,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -31,11 +30,6 @@ public void cleanProject() throws CoreException { deleteSrcContents(TEST_PROJECT); } - @After - public void cleanConsole() { - clearConsole(); - } - @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, @@ -83,10 +77,8 @@ public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - clearConsole(); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - clearConsole(); runProjectTest(TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index fe7fcb25..362b2a94 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -4,7 +4,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -30,11 +29,6 @@ public void cleanProject() throws CoreException { deleteSrcContents(TEST_PROJECT); } - @After - public void cleanConsole() { - clearConsole(); - } - @Test public void emptyClassAndEmptyTest() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); @@ -101,10 +95,8 @@ public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - clearConsole(); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - clearConsole(); runProjectTest(TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); } From 72d82d57fe2f2a0b7bf9e9672ac98e18c9a85db6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 14:51:09 +0200 Subject: [PATCH 41/82] 81: create classes only once per test case and then remove methods programmatically before each test Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pageobjects/AbstractSyntaxTree.java | 25 +++++++++++ .../ui/behaviours/steps/ClassSteps.java | 12 +++++ .../ui/tests/AbstractPitclipseSWTBotTest.java | 6 +++ .../ui/tests/PitclipseUiRunnerJUnit5Test.java | 34 ++++++++------ .../ui/tests/PitclipseUiRunnerTest.java | 44 ++++++++++--------- 5 files changed, 87 insertions(+), 34 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java index 16ce114b..55f9849a 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java @@ -69,6 +69,31 @@ public void addMethod(ConcreteClassContext context) { } } + public boolean hasMethods(ConcreteClassContext context) { + IJavaProject javaProject = getJavaProject(context); + try { + IType type = javaProject.findType(context.getFullyQualifiedTestClassName()); + IMethod[] methods = type.getMethods(); + return methods.length > 0; + } catch (JavaModelException e) { + throw new StepException(e); + } + } + + public void removeMethods(ConcreteClassContext context) { + IJavaProject javaProject = getJavaProject(context); + try { + IType type = javaProject.findType(context.getFullyQualifiedTestClassName()); + NullProgressMonitor progressMonitor = new NullProgressMonitor(); + IMethod[] methods = type.getMethods(); + for (IMethod method : methods) { + method.delete(true, progressMonitor); + } + } catch (JavaModelException e) { + throw new StepException(e); + } + } + public void deleteProject(String projectName) { NullProgressMonitor progressMonitor = new NullProgressMonitor(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java index 6e5bb638..c63edc64 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java @@ -87,6 +87,18 @@ public void createMethod(String method) { PAGES.getBuildProgress().waitForBuild(); } + public void removeMethods() { + if (!PAGES.getAbstractSyntaxTree().hasMethods(concreteClassContext)) + return; + PAGES.getBuildProgress().listenForBuild(); + PAGES.getPackageExplorer().openClass(concreteClassContext); + PAGES.getAbstractSyntaxTree().removeMethods(concreteClassContext); + PAGES.getSourceMenu().organizeImports(); + PAGES.getSourceMenu().format(); + PAGES.getFileMenu().saveAll(); + PAGES.getBuildProgress().waitForBuild(); + } + @When("the class is renamed to {word}") public void renameClass(String newClassName) { PAGES.getBuildProgress().listenForBuild(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 2aeef9eb..660dabcd 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -175,6 +175,12 @@ protected static void createMethod(String className, String packageName, String classSteps.createMethod(method); } + protected static void removeMethods(String className, String packageName, String projectName) { + ClassSteps classSteps = new ClassSteps(); + classSteps.selectClass(className, packageName, projectName); + classSteps.removeMethods(); + } + protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { new PitclipseSteps().runTest(testClassName, packageName, projectName); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java index a73235f8..b1d3c634 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java @@ -18,25 +18,31 @@ public class PitclipseUiRunnerJUnit5Test extends AbstractPitclipseSWTBotTest { private static final String TEST_PROJECT = "project1"; + private static final String FOO_BAR_PACKAGE = "foo.bar"; + private static final String FOO_CLASS = "Foo"; + private static final String FOO_TEST_CLASS = "FooTest"; @BeforeClass public static void setupJavaProject() { createJavaProjectWithJUnit5(TEST_PROJECT); verifyProjectExists(TEST_PROJECT); + createClass(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + createClass(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Before - public void cleanProject() throws CoreException { - deleteSrcContents(TEST_PROJECT); + public void cleanClasses() throws CoreException { + removeMethods(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest1() {Foo foo = new Foo();}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -45,11 +51,11 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { @Test public void classWithMethodAndBadTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest2() {new Foo().doFoo(1);}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 0, 0, 2, 1); mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -58,11 +64,11 @@ public void classWithMethodAndBadTestMethod() throws CoreException { @Test public void classWithMethodAndBetterTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -71,11 +77,11 @@ public void classWithMethodAndBetterTestMethod() throws CoreException { @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); - runPackageTest("foo.bar", TEST_PROJECT); + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index 362b2a94..2fcff651 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -17,44 +17,47 @@ public class PitclipseUiRunnerTest extends AbstractPitclipseSWTBotTest { private static final String TEST_PROJECT = "project1"; + private static final String FOO_BAR_PACKAGE = "foo.bar"; + private static final String FOO_CLASS = "Foo"; + private static final String FOO_TEST_CLASS = "FooTest"; @BeforeClass public static void setupJavaProject() { createJavaProjectWithJUnit4(TEST_PROJECT); verifyProjectExists(TEST_PROJECT); + createClass(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + createClass(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Before - public void cleanProject() throws CoreException { - deleteSrcContents(TEST_PROJECT); + public void cleanClasses() throws CoreException { + removeMethods(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Test public void emptyClassAndEmptyTest() throws CoreException { - createClass("Foo", "foo.bar", TEST_PROJECT); - createClass("FooTest", "foo.bar", TEST_PROJECT); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); } @Test public void emptyClassAndEmptyTestMethod() throws CoreException { - createClass("Foo", "foo.bar", TEST_PROJECT); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); } @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -63,11 +66,11 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { @Test public void classWithMethodAndBadTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@Test public void fooTest2() {new Foo().doFoo(1);}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 0, 0, 2, 1); mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -76,24 +79,25 @@ public void classWithMethodAndBadTestMethod() throws CoreException { @Test public void classWithMethodAndBetterTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); + removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); - runPackageTest("foo.bar", TEST_PROJECT); + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); From 645f90403604d5d7c24fd29f61eac464c55ad4b8 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 15:51:47 +0200 Subject: [PATCH 42/82] 81: don't do the full build before running PIT Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index 562f65b7..261e3912 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -37,10 +37,8 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; @@ -65,7 +63,7 @@ public class PitclipseSteps { @When("test {word} in package {word} is run for project {word}") public void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { // Build the whole workspace to prevent random compilation failures - ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); +// ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); runPit(new SelectTestClass(testClassName, packageName, projectName)); } From 06752a50f4f66879d2b3f3340510eb262e2de5d5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 15:52:41 +0200 Subject: [PATCH 43/82] 81: Also verify the PIT Summary Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitclipse/ui/behaviours/steps/PitclipseSteps.java | 3 +++ .../src/org/pitest/pitclipse/ui/swtbot/PitNotifier.java | 7 +++++-- .../pitest/pitclipse/ui/swtbot/PitResultNotifier.java | 8 +------- .../pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java | 3 +++ .../pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java | 9 ++++++++- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index 261e3912..a43799d3 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -50,6 +50,7 @@ import org.pitest.pitclipse.runner.results.DetectionStatus; import org.pitest.pitclipse.ui.behaviours.pageobjects.PackageContext; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitSummaryView; +import org.pitest.pitclipse.ui.swtbot.PitNotifier; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; @@ -141,6 +142,8 @@ private void runPit(Runnable runnable) { // make sure to clear the console to avoid interferences // with the output of previous runs PAGES.views().clearConsole(); + // make sure notifications not read are cleared + PitNotifier.INSTANCE.reset(); int retryCount = 20; int counter = 0; while (counter < retryCount) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitNotifier.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitNotifier.java index 20797e20..a467182a 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitNotifier.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitNotifier.java @@ -18,6 +18,9 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; public enum PitNotifier { INSTANCE; @@ -26,12 +29,12 @@ public enum PitNotifier { 1); public PitResultsView getResults() throws InterruptedException { - return resultQueue.take(); + return resultQueue.poll(SWTBotPreferences.TIMEOUT, TimeUnit.MILLISECONDS); } public void notifyResults(PitResultsView resultsView) throws InterruptedException { - resultQueue.put(resultsView); + resultQueue.offer(resultsView, SWTBotPreferences.TIMEOUT, TimeUnit.MILLISECONDS); } public void reset() { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java index ff845c8f..2c015a91 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java @@ -17,16 +17,13 @@ package org.pitest.pitclipse.ui.swtbot; import org.pitest.pitclipse.core.extension.point.ResultNotifier; -import org.pitest.pitclipse.ui.PitclipseTestActivator; import org.pitest.pitclipse.ui.extension.point.PitUiUpdate; import org.pitest.pitclipse.ui.swtbot.ResultsParser.Summary; public class PitResultNotifier implements ResultNotifier { @Override public void handleResults(PitUiUpdate updateEvent) { - if (testsAreInProgress()) { - notifiyTestsOfHtmlResults(updateEvent); - } + notifiyTestsOfHtmlResults(updateEvent); } private void notifiyTestsOfHtmlResults(PitUiUpdate updateEvent) { @@ -51,7 +48,4 @@ private void tryNotifyResults(PitResultsView view) { } } - private boolean testsAreInProgress() { - return PitclipseTestActivator.getDefault().areTestsInProgress(); - } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 660dabcd..e83027fd 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -263,4 +263,7 @@ protected static void mutationsAre(List expectedMutations) { assertThat(actualMutations, equalTo(expectedMutations)); } + protected static void coverageReportGenerated(int classes, double totalCoverage, double mutationCoverage) { + new PitclipseSteps().coverageReportGenerated(classes, totalCoverage, mutationCoverage); + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index 2fcff651..35f5c639 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -40,6 +40,7 @@ public void emptyClassAndEmptyTest() throws CoreException { runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); + coverageReportGenerated(0, 100, 100); } @Test @@ -49,6 +50,7 @@ public void emptyClassAndEmptyTestMethod() throws CoreException { runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); + coverageReportGenerated(0, 100, 100); } @Test @@ -62,6 +64,7 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); + coverageReportGenerated(1, 50, 0); } @Test @@ -75,6 +78,7 @@ public void classWithMethodAndBadTestMethod() throws CoreException { mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); + coverageReportGenerated(1, 100, 0); } @Test @@ -88,7 +92,7 @@ public void classWithMethodAndBetterTestMethod() throws CoreException { mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(1, 100, 100); } @Test @@ -99,10 +103,13 @@ public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); + coverageReportGenerated(1, 100, 100); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); + coverageReportGenerated(1, 100, 100); runProjectTest(TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); + coverageReportGenerated(1, 100, 100); } } From 9bde4a36073df2fd25c9fbc38f301ae928e9bb36 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 16:02:21 +0200 Subject: [PATCH 44/82] 81: Reverted: create classes only once per test case Seems to be worse and seems to make tests more flaky... probably because of some missed synchronization with the JDT model? Maybe it's better not to mess to much with JDT directly ;) Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pageobjects/AbstractSyntaxTree.java | 25 --------- .../ui/behaviours/steps/ClassSteps.java | 12 ----- .../ui/tests/AbstractPitclipseSWTBotTest.java | 6 --- .../ui/tests/PitclipseUiRunnerJUnit5Test.java | 34 +++++-------- .../ui/tests/PitclipseUiRunnerTest.java | 51 ++++++++----------- 5 files changed, 34 insertions(+), 94 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java index 55f9849a..16ce114b 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/AbstractSyntaxTree.java @@ -69,31 +69,6 @@ public void addMethod(ConcreteClassContext context) { } } - public boolean hasMethods(ConcreteClassContext context) { - IJavaProject javaProject = getJavaProject(context); - try { - IType type = javaProject.findType(context.getFullyQualifiedTestClassName()); - IMethod[] methods = type.getMethods(); - return methods.length > 0; - } catch (JavaModelException e) { - throw new StepException(e); - } - } - - public void removeMethods(ConcreteClassContext context) { - IJavaProject javaProject = getJavaProject(context); - try { - IType type = javaProject.findType(context.getFullyQualifiedTestClassName()); - NullProgressMonitor progressMonitor = new NullProgressMonitor(); - IMethod[] methods = type.getMethods(); - for (IMethod method : methods) { - method.delete(true, progressMonitor); - } - } catch (JavaModelException e) { - throw new StepException(e); - } - } - public void deleteProject(String projectName) { NullProgressMonitor progressMonitor = new NullProgressMonitor(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java index c63edc64..6e5bb638 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/ClassSteps.java @@ -87,18 +87,6 @@ public void createMethod(String method) { PAGES.getBuildProgress().waitForBuild(); } - public void removeMethods() { - if (!PAGES.getAbstractSyntaxTree().hasMethods(concreteClassContext)) - return; - PAGES.getBuildProgress().listenForBuild(); - PAGES.getPackageExplorer().openClass(concreteClassContext); - PAGES.getAbstractSyntaxTree().removeMethods(concreteClassContext); - PAGES.getSourceMenu().organizeImports(); - PAGES.getSourceMenu().format(); - PAGES.getFileMenu().saveAll(); - PAGES.getBuildProgress().waitForBuild(); - } - @When("the class is renamed to {word}") public void renameClass(String newClassName) { PAGES.getBuildProgress().listenForBuild(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index e83027fd..2d48cf05 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -175,12 +175,6 @@ protected static void createMethod(String className, String packageName, String classSteps.createMethod(method); } - protected static void removeMethods(String className, String packageName, String projectName) { - ClassSteps classSteps = new ClassSteps(); - classSteps.selectClass(className, packageName, projectName); - classSteps.removeMethods(); - } - protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { new PitclipseSteps().runTest(testClassName, packageName, projectName); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java index b1d3c634..a73235f8 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java @@ -18,31 +18,25 @@ public class PitclipseUiRunnerJUnit5Test extends AbstractPitclipseSWTBotTest { private static final String TEST_PROJECT = "project1"; - private static final String FOO_BAR_PACKAGE = "foo.bar"; - private static final String FOO_CLASS = "Foo"; - private static final String FOO_TEST_CLASS = "FooTest"; @BeforeClass public static void setupJavaProject() { createJavaProjectWithJUnit5(TEST_PROJECT); verifyProjectExists(TEST_PROJECT); - createClass(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); - createClass(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Before - public void cleanClasses() throws CoreException { - removeMethods(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); - removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + public void cleanProject() throws CoreException { + deleteSrcContents(TEST_PROJECT); } @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest1() {Foo foo = new Foo();}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -51,11 +45,11 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { @Test public void classWithMethodAndBadTestMethod() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest2() {new Foo().doFoo(1);}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 2, 1); mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -64,11 +58,11 @@ public void classWithMethodAndBadTestMethod() throws CoreException { @Test public void classWithMethodAndBetterTestMethod() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -77,11 +71,11 @@ public void classWithMethodAndBetterTestMethod() throws CoreException { @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); - runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); + runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index 35f5c639..362b2a94 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -17,99 +17,88 @@ public class PitclipseUiRunnerTest extends AbstractPitclipseSWTBotTest { private static final String TEST_PROJECT = "project1"; - private static final String FOO_BAR_PACKAGE = "foo.bar"; - private static final String FOO_CLASS = "Foo"; - private static final String FOO_TEST_CLASS = "FooTest"; @BeforeClass public static void setupJavaProject() { createJavaProjectWithJUnit4(TEST_PROJECT); verifyProjectExists(TEST_PROJECT); - createClass(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); - createClass(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Before - public void cleanClasses() throws CoreException { - removeMethods(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); - removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + public void cleanProject() throws CoreException { + deleteSrcContents(TEST_PROJECT); } @Test public void emptyClassAndEmptyTest() throws CoreException { - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + createClass("Foo", "foo.bar", TEST_PROJECT); + createClass("FooTest", "foo.bar", TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); - coverageReportGenerated(0, 100, 100); } @Test public void emptyClassAndEmptyTestMethod() throws CoreException { - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClass("Foo", "foo.bar", TEST_PROJECT); + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); - coverageReportGenerated(0, 100, 100); } @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest1() {Foo foo = new Foo();}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - coverageReportGenerated(1, 50, 0); } @Test public void classWithMethodAndBadTestMethod() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest2() {new Foo().doFoo(1);}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 2, 1); mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - coverageReportGenerated(1, 100, 0); } @Test public void classWithMethodAndBetterTestMethod() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); - runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - coverageReportGenerated(1, 100, 100); } @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { - createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, "public int doFoo(int i) {return i + 1;}"); - createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); - runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); + runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - coverageReportGenerated(1, 100, 100); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - coverageReportGenerated(1, 100, 100); runProjectTest(TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); - coverageReportGenerated(1, 100, 100); } } From 06c18cf53b2262784018d00ef8185ad78138fec5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 16:11:06 +0200 Subject: [PATCH 45/82] 81: Also verify the PIT Summary (2) Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index 362b2a94..a088b2e6 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -36,6 +36,7 @@ public void emptyClassAndEmptyTest() throws CoreException { runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); + coverageReportGenerated(0, 100, 100); } @Test @@ -46,6 +47,7 @@ public void emptyClassAndEmptyTestMethod() throws CoreException { runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); + coverageReportGenerated(0, 100, 100); } @Test @@ -59,6 +61,7 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); + coverageReportGenerated(1, 50, 0); } @Test @@ -72,6 +75,7 @@ public void classWithMethodAndBadTestMethod() throws CoreException { mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); + coverageReportGenerated(1, 100, 0); } @Test @@ -85,6 +89,7 @@ public void classWithMethodAndBetterTestMethod() throws CoreException { mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); + coverageReportGenerated(1, 100, 100); } @Test @@ -95,10 +100,13 @@ public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); + coverageReportGenerated(1, 100, 100); runPackageRootTest("src", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); + coverageReportGenerated(1, 100, 100); runProjectTest(TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); + coverageReportGenerated(1, 100, 100); } } From fe756d6baa9a5407013bc8dad799f7c5e62f7fd3 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 11 May 2021 16:13:45 +0200 Subject: [PATCH 46/82] 81: archive results also if cancelled Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 4 ++-- .github/workflows/windows-mac.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 08d53b09..e94be579 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,13 +46,13 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Archive Test Results uses: actions/upload-artifact@v2 - if: ${{ failure() }} + if: ${{ failure() }} || ${{ cancelled() }} with: name: test-results-${{ runner.os }} path: '**/*.tests/target' - name: Archive UI Tests Screenshots uses: actions/upload-artifact@v2 - if: ${{ failure() }} + if: ${{ failure() }} || ${{ cancelled() }} with: name: screenshots-${{ runner.os }} path: '**/*.tests/screenshots' diff --git a/.github/workflows/windows-mac.yml b/.github/workflows/windows-mac.yml index 8d586b47..227d573a 100644 --- a/.github/workflows/windows-mac.yml +++ b/.github/workflows/windows-mac.yml @@ -35,13 +35,13 @@ jobs: run: mvn '-Dtycho.disableP2Mirrors=true' verify - name: Archive Test Results uses: actions/upload-artifact@v2 - if: ${{ failure() }} + if: ${{ failure() }} || ${{ cancelled() }} with: name: test-results-${{ runner.os }} path: '**/*.tests/target' - name: Archive UI Tests Screenshots uses: actions/upload-artifact@v2 - if: ${{ failure() }} + if: ${{ failure() }} || ${{ cancelled() }} with: name: screenshots-${{ runner.os }} path: '**/*.tests/screenshots' From 0e42287d270d33932e6e8e91e3276313742aea4c Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 09:47:35 +0200 Subject: [PATCH 47/82] 81: Introduced setClassContents the contents of the class is not modified using the JDT model but by the Eclipse editor Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 69 +++++++++++++++++-- .../ui/tests/PitclipseUiRunnerJUnit5Test.java | 50 +++----------- .../ui/tests/PitclipseUiRunnerTest.java | 43 +++++++++--- 3 files changed, 108 insertions(+), 54 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 2d48cf05..a89b473d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -26,11 +26,14 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.ui.IWorkbench; @@ -42,7 +45,6 @@ import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.results.DetectionStatus; -import org.pitest.pitclipse.ui.behaviours.steps.ClassSteps; import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; @@ -153,6 +155,15 @@ protected static void addToBuildPath(String dependentProject, String projectName PAGES.getAbstractSyntaxTree().addProjectToClassPathOfProject(projectName, dependentProject); } + /** + * See {@link #setClassContents(String, String, String, String)} for the + * method specification. + * + * @param className + * @param packageName + * @param projectName + * @param method + */ protected static void createClassWithMethod(String className, String packageName, String projectName, String method) { createClass(className, packageName, projectName); @@ -168,11 +179,61 @@ protected static void createClass(String className, String packageName, String p PAGES.getBuildProgress().waitForBuild(); } + /** + * See {@link #setClassContents(String, String, String, String)} for the + * method specification. + * + * @param className + * @param packageName + * @param projectName + * @param method + */ protected static void createMethod(String className, String packageName, String projectName, String method) { - ClassSteps classSteps = new ClassSteps(); - classSteps.selectClass(className, packageName, projectName); - classSteps.createMethod(method); + setClassContents(className, packageName, projectName, method); + } + + /** + * Sets the class contents: the package declaration and the class declaration + * are generated automatically, and only the contents to be inserted inside the class + * must be specified (thus, all types must be fully qualified since there's no way + * of specifying the imports). + * + * Example: + * + *
+     * setClassContents("FooTest", "foo.bar", TEST_PROJECT,
+     *          "@org.junit.Test\n"
+     *        + "public void fooTest3() {\n"
+     *        + "    org.junit.Assert.assertEquals(2,\n"
+     *        + "            new Foo().doFoo(1));\n"
+     *        + "}");
+     * 
+ * + * @param className + * @param packageName + * @param project + * @param contents + */ + protected static void setClassContents(String className, String packageName, String project, + String contents) { + PAGES.getBuildProgress().listenForBuild(); + SWTBotEditor editor = bot.editorByTitle(className + ".java"); + editor.setFocus(); + editor.toTextEditor().setText( + "package " + packageName + ";\n\n" + + "public class " + className + " {\n\n" + + indent(contents) + "\n\n" + + "}\n" + ); + editor.save(); + PAGES.getBuildProgress().waitForBuild(); + } + + private static String indent(String contents) { + return Stream.of(contents.split("\n")) + .map(s -> " " + s) + .collect(Collectors.joining("\n")); } protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java index a73235f8..2ddc9542 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerJUnit5Test.java @@ -30,51 +30,19 @@ public void cleanProject() throws CoreException { deleteSrcContents(TEST_PROJECT); } - @Test - public void classWithMethodAndNoCoverageTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@org.junit.jupiter.api.Test public void fooTest1() {Foo foo = new Foo();}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); - consoleContains(2, 0, 0, 0, 0); - mutationsAre( - "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + - "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - } - - @Test - public void classWithMethodAndBadTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@org.junit.jupiter.api.Test public void fooTest2() {new Foo().doFoo(1);}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); - consoleContains(2, 0, 0, 2, 1); - mutationsAre( - "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + - "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - } - - @Test - public void classWithMethodAndBetterTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); - consoleContains(2, 2, 100, 2, 1); - mutationsAre( - "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + - "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo "); - } - @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); + "public int doFoo(int i) {\n" + + " return i + 1;\n" + + "}"); createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@org.junit.jupiter.api.Test public void fooTest3() {org.junit.jupiter.api.Assertions.assertEquals(2, new Foo().doFoo(1));}"); + "@org.junit.jupiter.api.Test\n" + + "public void fooTest3() {\n" + + " org.junit.jupiter.api.Assertions\n" + + " .assertEquals(2,\n" + + " new Foo().doFoo(1));\n" + + "}"); runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); runPackageRootTest("src", TEST_PROJECT); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index a088b2e6..baac7501 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -43,7 +43,10 @@ public void emptyClassAndEmptyTest() throws CoreException { public void emptyClassAndEmptyTestMethod() throws CoreException { createClass("Foo", "foo.bar", TEST_PROJECT); createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@Test public void fooTest1() {Foo foo = new Foo();}"); + "@org.junit.Test\n" + + "public void fooTest1() {\n" + + " Foo foo = new Foo();\n" + + "}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); @@ -53,9 +56,14 @@ public void emptyClassAndEmptyTestMethod() throws CoreException { @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); + "public int doFoo(int i) {\n" + + " return i + 1;\n" + + "}"); createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@Test public void fooTest1() {Foo foo = new Foo();}"); + "@org.junit.Test\n" + + "public void fooTest1() {\n" + + " Foo foo = new Foo();\n" + + "}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); mutationsAre( @@ -67,9 +75,14 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { @Test public void classWithMethodAndBadTestMethod() throws CoreException { createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); + "public int doFoo(int i) {\n" + + " return i + 1;\n" + + "}"); createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@Test public void fooTest2() {new Foo().doFoo(1);}"); + "@org.junit.Test\n" + + "public void fooTest2() {\n" + + " new Foo().doFoo(1);\n" + + "}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 0, 0, 2, 1); mutationsAre( @@ -81,9 +94,15 @@ public void classWithMethodAndBadTestMethod() throws CoreException { @Test public void classWithMethodAndBetterTestMethod() throws CoreException { createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); + "public int doFoo(int i) {\n" + + " return i + 1;\n" + + "}"); createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); + "@org.junit.Test\n" + + "public void fooTest3() {\n" + + " org.junit.Assert.assertEquals(2,\n" + + " new Foo().doFoo(1));\n" + + "}"); runTest("FooTest", "foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); mutationsAre( @@ -95,9 +114,15 @@ public void classWithMethodAndBetterTestMethod() throws CoreException { @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, - "public int doFoo(int i) {return i + 1;}"); + "public int doFoo(int i) {\n" + + " return i + 1;\n" + + "}"); createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@Test public void fooTest3() {org.junit.Assert.assertEquals(2, new Foo().doFoo(1));}"); + "@org.junit.Test\n" + + "public void fooTest3() {\n" + + " org.junit.Assert.assertEquals(2,\n" + + " new Foo().doFoo(1));\n" + + "}"); runPackageTest("foo.bar", TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); coverageReportGenerated(1, 100, 100); From 63b4ae88805950a18120f2b97c617bcd5922717b Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 09:52:15 +0200 Subject: [PATCH 48/82] 81: removed attempt to clean the project That did not actually cleaned the workspace. Moreover, synchronization with build should be fixed now. Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/behaviours/steps/PitclipseSteps.java | 44 +------------------ 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index a43799d3..19686875 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -39,8 +39,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.widgets.TimeoutException; import org.hamcrest.Description; @@ -138,7 +136,7 @@ public void runtimeOptionsMatch(DataTable configTable) { } private void runPit(Runnable runnable) { - assertPitCanRun(); + assertNoErrorsInWorkspace(); // make sure to clear the console to avoid interferences // with the output of previous runs PAGES.views().clearConsole(); @@ -164,46 +162,6 @@ public void assertNoErrorsInWorkspace() { assertThat(errors, empty()); } - /** - * This method is an attempt to "fix" a flaky test, or at least - * to reduce its effects by: - * 1) failing fast (instead of freezing the whole build) - * 2) giving details about the failure - * - * The test seems to be flaky because of compilation errors produced - * by missing imports and that's why this method uses 'auto import' - * on all open editors as an attempt to work around the issue. - * - * See https://github.com/pitest/pitclipse/issues/81 - */ - private final void assertPitCanRun() { - Set errors = errorsInWorkspace(); - if (errors.isEmpty()) { - // So far, so good. Let's run PIT. - return; - } - PAGES.getBuildProgress().listenForBuild(); - for (SWTBotEditor editor : new SWTWorkbenchBot().editors()) { - editor.setFocus(); - try { - PAGES.getSourceMenu().organizeImports(); - PAGES.getSourceMenu().format(); - } catch (TimeoutException e) { - System.err.println("Errors have been found, but attempt to fix them failed on editor " + editor.getTitle() + " => " + e.getMessage()); - } - } - PAGES.getBuildProgress().waitForBuild(); - Set errorsAfterCleaning = errorsInWorkspace(); - if (! errorsAfterCleaning.isEmpty()) { - throw new IllegalStateException("Unexpected errors may prevent PIT from running. This is likely due to a flaky test; please relaunch the build." + - "\n Errors are: " + errorsAfterCleaning); - } - else { - System.err.println("Unexpected errors have been detected before running PIT but have been succesfully fixed." + - "\n Errors were: " + errors); - } - } - /** * Makes sure there are no errors in the Workspace, by accessing the error * markers directly. From 527b65be6cd11d389d9e3552b0f56c6036b8a548 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 10:28:11 +0200 Subject: [PATCH 49/82] 81: open preferences Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 7 ++++++ .../ui/tests/PitclipseOptionsTest.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index a89b473d..4980b9f0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -54,6 +54,9 @@ */ @RunWith(SWTBotJunit4ClassRunner.class) public abstract class AbstractPitclipseSWTBotTest { + private static final String WINDOWS = "Window"; + private static final String PREFERENCES = "Preferences"; + protected static SWTWorkbenchBot bot; @BeforeClass @@ -321,4 +324,8 @@ protected static void mutationsAre(List expectedMutations) { protected static void coverageReportGenerated(int classes, double totalCoverage, double mutationCoverage) { new PitclipseSteps().coverageReportGenerated(classes, totalCoverage, mutationCoverage); } + + protected static void openPreferences() { + bot.menu(WINDOWS).menu(PREFERENCES).click(); + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java new file mode 100644 index 00000000..70586cbc --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -0,0 +1,24 @@ +package org.pitest.pitclipse.ui.tests; + +import java.util.Collections; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author Lorenzo Bettini + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class PitclipseOptionsTest extends AbstractPitclipseSWTBotTest { + + @Test + public void defaultOptions() { + openPreferences(); + } + +} From 09b64e1373e610b3f1ef5cdb88882ac8635edae8 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 10:40:07 +0200 Subject: [PATCH 50/82] 81: Use the shortcut on macOS to open the preferences Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 4980b9f0..5c6f40f5 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -31,11 +31,15 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jface.bindings.keys.IKeyLookup; +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; @@ -326,6 +330,16 @@ protected static void coverageReportGenerated(int classes, double totalCoverage, } protected static void openPreferences() { - bot.menu(WINDOWS).menu(PREFERENCES).click(); + if (SWTUtils.isMac()) { + // On Mac, we use the keyboard shortcut. + try { + bot.activeShell().pressShortcut(KeyStroke.getInstance + (IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(",")); + } catch (ParseException e) { + fail(e.getMessage()); + } + } else { + bot.menu(WINDOWS).menu(PREFERENCES).click(); + } } } From 94ef2672c3f918de75e14601138042b3de4202c6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 10:58:03 +0200 Subject: [PATCH 51/82] 81: some tests with preferences Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pageobjects/PitPreferenceSelector.java | 17 ++++---------- .../behaviours/pageobjects/WindowsMenu.java | 23 ++++++++++++++++--- .../ui/tests/AbstractPitclipseSWTBotTest.java | 20 ---------------- .../ui/tests/PitclipseOptionsTest.java | 16 +++++++++---- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index 61063749..a53c1624 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -52,7 +52,6 @@ public void setPitExecutionMode(PitExecutionMode mode) { activatePreferenceShell(); expandPitPreferences(); selectExecutionMode(mode); - close(); } private void selectExecutionMode(PitExecutionMode mode) { @@ -164,12 +163,8 @@ public PreferenceGetterBuilder(PreferenceGetter getter) { public T from(String label) { activatePreferenceShell(); - try { - expandPitPreferences(); - return getter.getPreference(label); - } finally { - close(); - } + expandPitPreferences(); + return getter.getPreference(label); } } @@ -209,12 +204,8 @@ public void to(final int value) { private void updatePreference(PreferenceSetter s) { activatePreferenceShell(); - try { - expandPitPreferences(); - s.setPreference(); - } finally { - close(); - } + expandPitPreferences(); + s.setPreference(); } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index 5877ed9e..d628d5e1 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -16,11 +16,17 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; +import org.eclipse.jface.bindings.keys.IKeyLookup; +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.PitMutators; import org.pitest.pitclipse.runner.config.PitExecutionMode; +import static org.junit.Assert.fail; + import java.math.BigDecimal; public class WindowsMenu { @@ -102,8 +108,19 @@ public String getExcludedClasses() { return preferenceSelector.getExcludedClasses(); } - private PreferenceDsl openPreferences() { - bot.menu(WINDOWS).menu(PREFERENCES).click(); + public PreferenceDsl openPreferences() { + if (SWTUtils.isMac()) { + // On Mac, we use the keyboard shortcut. + try { + bot.activeShell().pressShortcut(KeyStroke.getInstance + (IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(",")); + } catch (ParseException e) { + fail(e.getMessage()); + } + } else { + bot.menu(WINDOWS).menu(PREFERENCES).click(); + } + bot.shell(PREFERENCES).activate(); return new PreferenceDsl(); } @@ -161,7 +178,7 @@ public BigDecimal getTimeoutFactor() { return openPreferences().andThen().getPitTimeoutFactor(); } - private class PreferenceDsl { + public class PreferenceDsl { public PitPreferenceSelector andThen() { return preferenceSelector; } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 5c6f40f5..839b5676 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -31,15 +31,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jface.bindings.keys.IKeyLookup; -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; @@ -58,9 +54,6 @@ */ @RunWith(SWTBotJunit4ClassRunner.class) public abstract class AbstractPitclipseSWTBotTest { - private static final String WINDOWS = "Window"; - private static final String PREFERENCES = "Preferences"; - protected static SWTWorkbenchBot bot; @BeforeClass @@ -329,17 +322,4 @@ protected static void coverageReportGenerated(int classes, double totalCoverage, new PitclipseSteps().coverageReportGenerated(classes, totalCoverage, mutationCoverage); } - protected static void openPreferences() { - if (SWTUtils.isMac()) { - // On Mac, we use the keyboard shortcut. - try { - bot.activeShell().pressShortcut(KeyStroke.getInstance - (IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(",")); - } catch (ParseException e) { - fail(e.getMessage()); - } - } else { - bot.menu(WINDOWS).menu(PREFERENCES).click(); - } - } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 70586cbc..d48376b0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -1,13 +1,15 @@ package org.pitest.pitclipse.ui.tests; -import java.util.Collections; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; +import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; -import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.pitest.pitclipse.ui.behaviours.pageobjects.PitPreferenceSelector; /** * @author Lorenzo Bettini @@ -18,7 +20,11 @@ public class PitclipseOptionsTest extends AbstractPitclipseSWTBotTest { @Test public void defaultOptions() { - openPreferences(); + PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); + assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode()); + assertTrue(selector.isPitRunInParallel()); + assertFalse(selector.isIncrementalAnalysisEnabled()); + selector.close(); } } From f4ecbc5160da246284fb5223195f21c4a6a592aa Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 12:06:00 +0200 Subject: [PATCH 52/82] 81: wait for preferences to be active Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index d628d5e1..72d5057b 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -21,6 +21,7 @@ import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.utils.SWTUtils; +import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.PitMutators; import org.pitest.pitclipse.runner.config.PitExecutionMode; @@ -120,6 +121,7 @@ public PreferenceDsl openPreferences() { } else { bot.menu(WINDOWS).menu(PREFERENCES).click(); } + bot.waitUntil(Conditions.shellIsActive(PREFERENCES)); bot.shell(PREFERENCES).activate(); return new PreferenceDsl(); } From b583e20e7b70a5c9a8b52ec09f1171c76a0733e2 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 14:01:08 +0200 Subject: [PATCH 53/82] 81: increased SWTBot timeout in launch Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../org.pitest.pitclipse.ui.tests.launch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch index 3e7b377f..7df304b7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch +++ b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch @@ -28,7 +28,7 @@ - + From 42b3ffff1be19d58f39e2baff09f15b4aa93a4b6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 14:01:33 +0200 Subject: [PATCH 54/82] 81: Open Preferences programmatically in mac Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../behaviours/pageobjects/WindowsMenu.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index 72d5057b..4a9024e2 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -16,20 +16,18 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; -import org.eclipse.jface.bindings.keys.IKeyLookup; -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.bindings.keys.ParseException; +import java.math.BigDecimal; + +import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.eclipse.swtbot.swt.finder.waits.Conditions; +import org.eclipse.ui.dialogs.PreferencesUtil; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.PitMutators; import org.pitest.pitclipse.runner.config.PitExecutionMode; -import static org.junit.Assert.fail; - -import java.math.BigDecimal; - public class WindowsMenu { private static final String WINDOWS = "Window"; @@ -111,13 +109,14 @@ public String getExcludedClasses() { public PreferenceDsl openPreferences() { if (SWTUtils.isMac()) { - // On Mac, we use the keyboard shortcut. - try { - bot.activeShell().pressShortcut(KeyStroke.getInstance - (IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(",")); - } catch (ParseException e) { - fail(e.getMessage()); - } + // on macOS we cannot open the Preferences dialog + // (it's under the application name and we cannot access it, + // using the keyboard shortcut does not seem to work either) + UIThreadRunnable.asyncExec(() -> { + PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( + bot.activeShell().widget, null, null, null); + dialog.open(); + }); } else { bot.menu(WINDOWS).menu(PREFERENCES).click(); } From c0e7ad623070cefb5bdba657801e5a9d4e020290 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 14:42:57 +0200 Subject: [PATCH 55/82] 81: remaining tests for default preferences Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitclipse/ui/tests/PitclipseOptionsTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index d48376b0..a65d664a 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -1,11 +1,17 @@ package org.pitest.pitclipse.ui.tests; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; +import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_MUTATORS; import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; +import java.math.BigDecimal; + import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.Test; import org.junit.runner.RunWith; @@ -24,6 +30,13 @@ public void defaultOptions() { assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode()); assertTrue(selector.isPitRunInParallel()); assertFalse(selector.isIncrementalAnalysisEnabled()); + assertEquals("The 'Excluded Classes' preference has not the expected value", + "*Test", selector.getExcludedClasses()); + assertTrue(selector.getExcludedMethods().isEmpty()); + assertThat(selector.getAvoidCallsTo(), equalTo(DEFAULT_AVOID_CALLS_TO_LIST)); + assertThat(selector.getTimeout(), equalTo(3000)); + assertEquals(selector.getPitTimeoutFactor(), new BigDecimal(1.25)); + assertThat(selector.getMutators().toString(), equalTo(DEFAULT_MUTATORS)); selector.close(); } From 0b058ceb42825b174339f08e30ebc86e383e6a0a Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 14:58:09 +0200 Subject: [PATCH 56/82] include other bundles in JaCoCo reports --- .../pom.xml | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml b/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml index e81e0f43..bc582c82 100644 --- a/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml +++ b/tests/org.pitest.pitclipse.tests.coverage.report/pom.xml @@ -40,6 +40,36 @@ + + org.pitest + org.pitest.pitclipse.core + ${project.version} + compile + + + org.pitest + org.pitest.pitclipse.launch + ${project.version} + compile + + + org.pitest + org.pitest.pitclipse.launch.ui + ${project.version} + compile + + + org.pitest + org.pitest.pitclipse.listeners + ${project.version} + compile + + + org.pitest + org.pitest.pitclipse.preferences.ui + ${project.version} + compile + org.pitest org.pitest.pitclipse.runner From 798593ab8b806f59737479cf146d67fd70ee9119 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 16:11:48 +0200 Subject: [PATCH 57/82] 81: test enabling STRONGER mutators Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/PitclipseOptionsTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index a65d664a..3e78ce17 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.pitest.pitclipse.core.PitMutators.STRONGER; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_MUTATORS; import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; @@ -12,9 +13,11 @@ import java.math.BigDecimal; +import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.Test; import org.junit.runner.RunWith; +import org.pitest.pitclipse.core.PitMutators; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitPreferenceSelector; /** @@ -24,6 +27,13 @@ @RunWith(SWTBotJunit4ClassRunner.class) public class PitclipseOptionsTest extends AbstractPitclipseSWTBotTest { + private static final String TEST_PROJECT = "project1"; + 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 BAR_CLASS = "Bar"; + private static final String BAR_TEST_CLASS = "BarTest"; + @Test public void defaultOptions() { PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); @@ -40,4 +50,63 @@ public void defaultOptions() { selector.close(); } + @Test + public void useStrongerMutators() throws CoreException { + createJavaProjectWithJUnit4(TEST_PROJECT); + verifyProjectExists(TEST_PROJECT); + createClassWithMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "public int f(int i) {\n" + + " java.util.ArrayList pointless = new java.util.ArrayList<>();\n" + + " if (pointless.size() == 1)\n" + + " return i + 1;\n" + + " else\n" + + " return 0;\n" + + "}"); + createClassWithMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "@org.junit.Test public void badTest() {\n" + + " " + FOO_CLASS + " x = new " + FOO_CLASS + "();\n" + + " x.f(1);\n" + + "}"); + createClassWithMethod(BAR_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "public int f(int i) {\n" + + " java.util.ArrayList pointless = new java.util.ArrayList<>();\n" + + " if (pointless.size() == 1)\n" + + " return i + 1;\n" + + " else\n" + + " return 0;\n" + + "}"); + createClassWithMethod(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "@org.junit.Test public void badTest() {\n" + + " " + BAR_CLASS + " x = new " + BAR_CLASS + "();\n" + + " x.f(1);\n" + + "}"); + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 80, 0); + mutationsAre( + "SURVIVED | project1 | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Bar | 8 | replaced int return with 0 for foo/bar/Bar::f\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); + + // now set STRONGER mutators + PAGES.getWindowsMenu().setMutators(STRONGER); + try { + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 80, 0); + mutationsAre( + "SURVIVED | project1 | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "SURVIVED | project1 | foo.bar | foo.bar.Bar | 7 | removed conditional - replaced equality check with false\n" + + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 7 | removed conditional - replaced equality check with false\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Bar | 8 | replaced int return with 0 for foo/bar/Bar::f\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); + } finally { + // it's crucial to reset it to the default or we break other tests + PAGES.getWindowsMenu().setMutators(PitMutators.DEFAULTS); + } + } } From b69bf3dc1d765c8f847204fadeff01d29dade7ed Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 19:16:29 +0200 Subject: [PATCH 58/82] 81: test selection in PitMutationsView Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/view/mutations/PitMutationsView.java | 1 - .../pageobjects/PitMutationsView.java | 2 +- .../ui/behaviours/steps/PitclipseSteps.java | 4 ++ .../ui/tests/AbstractPitclipseSWTBotTest.java | 37 ++++++----- .../tests/PitclipsePitMutationsViewTest.java | 66 +++++++++++++++++++ 5 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java diff --git a/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/view/mutations/PitMutationsView.java b/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/view/mutations/PitMutationsView.java index 26d86e2a..f9ff3b44 100644 --- a/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/view/mutations/PitMutationsView.java +++ b/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/view/mutations/PitMutationsView.java @@ -39,7 +39,6 @@ private void createTreeViewer(Composite parent) { viewer.setLabelProvider(new ViewLabelProvider()); viewer.addDoubleClickListener(ExpandingDoubleClick.LISTENER); viewer.addDoubleClickListener(OpenMutationDoubleClick.LISTENER); - // viewer.addSelectionChangedListener(listener); viewer.setInput(MutationsModel.EMPTY_MODEL); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java index 5ad72307..bec966b0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsView.java @@ -50,12 +50,12 @@ public PitMutationsView(SWTWorkbenchBot bot) { } public List getMutations() { - PAGES.views().waitForTestsAreRunOnConsole(); SWTBotTree mutationTree = mutationTreeRoot(); return mutationsFrom(mutationTree); } private SWTBotTree mutationTreeRoot() { + PAGES.views().waitForTestsAreRunOnConsole(); SWTBotView mutationsView = bot.viewByTitle("PIT Mutations"); mutationsView.show(); // Make sure the 'PIT Mutations' view is opened diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index 19686875..77ab1693 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -91,6 +91,10 @@ public void mutationsAre(DataTable tableOfMutations) { @When("the following mutation is selected") public void mutationIsSelected(DataTable tableOfMutations) { PitMutation mutation = mutationsFromExampleTable(tableOfMutations).get(0); + mutationIsSelected(mutation); + } + + public void mutationIsSelected(PitMutation mutation) { PAGES.getPitMutationsView() .select(mutation); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 839b5676..177d214f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -55,6 +55,12 @@ @RunWith(SWTBotJunit4ClassRunner.class) public abstract class AbstractPitclipseSWTBotTest { protected static SWTWorkbenchBot bot; + private static int statusIndex = 0; + private static int projectIndex = 1; + private static int packageIndex = 2; + private static int classIndex = 3; + private static int lineIndex = 4; + private static int mutationIndex = 5; @BeforeClass public static void beforeClass() throws Exception { @@ -292,27 +298,26 @@ protected static void consoleContains(int generatedMutants, int killedMutants, protected static void mutationsAre(String expectedMutationsTable) { List expectedMutations = new ArrayList<>(); String[] lines = expectedMutationsTable.split("\n"); - final int statusIndex = 0; - final int projectIndex = 1; - final int packageIndex = 2; - final int classIndex = 3; - final int lineIndex = 4; - final int mutationIndex = 5; - for (String string : lines) { - String[] mutationRow = string.split("\\|"); - DetectionStatus status = DetectionStatus.valueOf(mutationRow[statusIndex].trim()); - String project = mutationRow[projectIndex].trim(); - String pkg = mutationRow[packageIndex].trim(); - String className = mutationRow[classIndex].trim(); - int line = parseInt(mutationRow[lineIndex].trim()); - String mutation = mutationRow[mutationIndex].trim(); - PitMutation pitMutation = PitMutation.builder().withStatus(status).withProject(project).withPackage(pkg) - .withClassName(className).withLineNumber(line).withMutation(mutation).build(); + for (String line : lines) { + PitMutation pitMutation = fromMutationLine(line); expectedMutations.add(pitMutation); } mutationsAre(expectedMutations); } + protected static PitMutation fromMutationLine(String line) { + String[] mutationRow = line.split("\\|"); + DetectionStatus status = DetectionStatus.valueOf(mutationRow[statusIndex].trim()); + String project = mutationRow[projectIndex].trim(); + String pkg = mutationRow[packageIndex].trim(); + String className = mutationRow[classIndex].trim(); + int lineNum = parseInt(mutationRow[lineIndex].trim()); + String mutation = mutationRow[mutationIndex].trim(); + PitMutation pitMutation = PitMutation.builder().withStatus(status).withProject(project).withPackage(pkg) + .withClassName(className).withLineNumber(lineNum).withMutation(mutation).build(); + return pitMutation; + } + protected static void mutationsAre(List expectedMutations) { List actualMutations = PAGES.getPitMutationsView().getMutations(); assertThat(actualMutations, equalTo(expectedMutations)); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java new file mode 100644 index 00000000..aa1243ae --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java @@ -0,0 +1,66 @@ +package org.pitest.pitclipse.ui.tests; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; +import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; + +/** + * @author Lorenzo Bettini + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class PitclipsePitMutationsViewTest extends AbstractPitclipseSWTBotTest { + + private static final String TEST_PROJECT = "project1"; + 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 BAR_CLASS = "Bar"; + private static final String BAR_TEST_CLASS = "BarTest"; + + @Test + public void selectMutationOpensTheClassAtTheRightLineNumber() throws CoreException { + createJavaProjectWithJUnit4(TEST_PROJECT); + verifyProjectExists(TEST_PROJECT); + createClassWithMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "public int f(int i) {\n" + + " java.util.ArrayList pointless = new java.util.ArrayList<>();\n" + + " if (pointless.size() == 1)\n" + + " return i + 1;\n" + + " else\n" + + " return 0;\n" + + "}"); + createClassWithMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "@org.junit.Test public void badTest() {\n" + + " " + FOO_CLASS + " x = new " + FOO_CLASS + "();\n" + + " x.f(1);\n" + + "}"); + createClassWithMethod(BAR_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "public int f(int i) {\n" + + " java.util.ArrayList pointless = new java.util.ArrayList<>();\n" + + " if (pointless.size() == 1)\n" + + " return i + 1;\n" + + " else\n" + + " return 0;\n" + + "}"); + createClassWithMethod(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "@org.junit.Test public void badTest() {\n" + + " " + BAR_CLASS + " x = new " + BAR_CLASS + "();\n" + + " x.f(1);\n" + + "}"); + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 80, 0); + PitclipseSteps pitclipseSteps = new PitclipseSteps(); + PitMutation mutation = fromMutationLine( + "SURVIVED | project1 | foo.bar | foo.bar.Foo | 7 | negated conditional"); + pitclipseSteps.mutationIsSelected(mutation); + pitclipseSteps.mutationIsOpened(FOO_CLASS + ".java", 7); + mutation = fromMutationLine( + "SURVIVED | project1 | foo.bar | foo.bar.Bar | 7 | negated conditional"); + pitclipseSteps.mutationIsSelected(mutation); + pitclipseSteps.mutationIsOpened(BAR_CLASS + ".java", 7); + } +} From 0564e8fdeace236f14002f1a65529cdee6781cfa Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 12 May 2021 19:25:20 +0200 Subject: [PATCH 59/82] 81: archive results also if cancelled FIXED Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .github/workflows/maven.yml | 4 ++-- .github/workflows/windows-mac.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e94be579..51c694c1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,13 +46,13 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Archive Test Results uses: actions/upload-artifact@v2 - if: ${{ failure() }} || ${{ cancelled() }} + if: ${{ failure() || cancelled() }} with: name: test-results-${{ runner.os }} path: '**/*.tests/target' - name: Archive UI Tests Screenshots uses: actions/upload-artifact@v2 - if: ${{ failure() }} || ${{ cancelled() }} + if: ${{ failure() || cancelled() }} with: name: screenshots-${{ runner.os }} path: '**/*.tests/screenshots' diff --git a/.github/workflows/windows-mac.yml b/.github/workflows/windows-mac.yml index 227d573a..0f6aa97d 100644 --- a/.github/workflows/windows-mac.yml +++ b/.github/workflows/windows-mac.yml @@ -35,13 +35,13 @@ jobs: run: mvn '-Dtycho.disableP2Mirrors=true' verify - name: Archive Test Results uses: actions/upload-artifact@v2 - if: ${{ failure() }} || ${{ cancelled() }} + if: ${{ failure() || cancelled() }} with: name: test-results-${{ runner.os }} path: '**/*.tests/target' - name: Archive UI Tests Screenshots uses: actions/upload-artifact@v2 - if: ${{ failure() }} || ${{ cancelled() }} + if: ${{ failure() || cancelled() }} with: name: screenshots-${{ runner.os }} path: '**/*.tests/screenshots' From bf64195e0b6cbf612ee289f1aae5f0787d6db4de Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 10:14:44 +0200 Subject: [PATCH 60/82] 81: create the classes only once in UI runner test Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 4 ++ .../ui/tests/PitclipseUiRunnerTest.java | 55 +++++++++---------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 177d214f..9116a9e4 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -236,6 +236,10 @@ protected static void setClassContents(String className, String packageName, Str PAGES.getBuildProgress().waitForBuild(); } + protected static void removeMethods(String className, String packageName, String project) { + setClassContents(className, packageName, project, "\n\n"); + } + private static String indent(String contents) { return Stream.of(contents.split("\n")) .map(s -> " " + s) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index baac7501..e5ba20f6 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -4,7 +4,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,23 +16,23 @@ public class PitclipseUiRunnerTest extends AbstractPitclipseSWTBotTest { private static final String TEST_PROJECT = "project1"; + private static final String FOO_BAR_PACKAGE = "foo.bar"; + private static final String FOO_CLASS = "Foo"; + private static final String FOO_TEST_CLASS = "FooTest"; @BeforeClass public static void setupJavaProject() { createJavaProjectWithJUnit4(TEST_PROJECT); verifyProjectExists(TEST_PROJECT); - } - - @Before - public void cleanProject() throws CoreException { - deleteSrcContents(TEST_PROJECT); + createClass(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + createClass(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); } @Test public void emptyClassAndEmptyTest() throws CoreException { - createClass("Foo", "foo.bar", TEST_PROJECT); - createClass("FooTest", "foo.bar", TEST_PROJECT); - runTest("FooTest", "foo.bar", TEST_PROJECT); + removeMethods(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + removeMethods(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); coverageReportGenerated(0, 100, 100); @@ -41,13 +40,13 @@ public void emptyClassAndEmptyTest() throws CoreException { @Test public void emptyClassAndEmptyTestMethod() throws CoreException { - createClass("Foo", "foo.bar", TEST_PROJECT); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, - "@org.junit.Test\n" - + "public void fooTest1() {\n" - + " Foo foo = new Foo();\n" - + "}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + removeMethods(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, + "@org.junit.Test\n" + + "public void fooTest1() {\n" + + " Foo foo = new Foo();\n" + + "}"); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(0, 0, 100, 0, 0); mutationsAre(Collections.emptyList()); coverageReportGenerated(0, 100, 100); @@ -55,16 +54,16 @@ public void emptyClassAndEmptyTestMethod() throws CoreException { @Test public void classWithMethodAndNoCoverageTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {\n" + " return i + 1;\n" + "}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.Test\n" + "public void fooTest1() {\n" + " Foo foo = new Foo();\n" + "}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 0, 0, 0, 0); mutationsAre( "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -74,16 +73,16 @@ public void classWithMethodAndNoCoverageTestMethod() throws CoreException { @Test public void classWithMethodAndBadTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {\n" + " return i + 1;\n" + "}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.Test\n" + "public void fooTest2() {\n" + " new Foo().doFoo(1);\n" + "}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 0, 0, 2, 1); mutationsAre( "SURVIVED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -93,17 +92,17 @@ public void classWithMethodAndBadTestMethod() throws CoreException { @Test public void classWithMethodAndBetterTestMethod() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {\n" + " return i + 1;\n" + "}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.Test\n" + "public void fooTest3() {\n" + " org.junit.Assert.assertEquals(2,\n" + " new Foo().doFoo(1));\n" + "}"); - runTest("FooTest", "foo.bar", TEST_PROJECT); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); mutationsAre( "KILLED | project1 | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" + @@ -113,17 +112,17 @@ public void classWithMethodAndBetterTestMethod() throws CoreException { @Test public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException { - createClassWithMethod("Foo", "foo.bar", TEST_PROJECT, + createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "public int doFoo(int i) {\n" + " return i + 1;\n" + "}"); - createClassWithMethod("FooTest", "foo.bar", TEST_PROJECT, + createMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, "@org.junit.Test\n" + "public void fooTest3() {\n" + " org.junit.Assert.assertEquals(2,\n" + " new Foo().doFoo(1));\n" + "}"); - runPackageTest("foo.bar", TEST_PROJECT); + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); consoleContains(2, 2, 100, 2, 1); coverageReportGenerated(1, 100, 100); runPackageRootTest("src", TEST_PROJECT); From 92707143b9e99375e5151b3ee386a5f29b66d01f Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 11:18:04 +0200 Subject: [PATCH 61/82] 81: create the classes only once in options test Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/PitclipseOptionsTest.java | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 3e78ce17..ddd916e7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitMutators; @@ -34,24 +35,8 @@ public class PitclipseOptionsTest extends AbstractPitclipseSWTBotTest { private static final String BAR_CLASS = "Bar"; private static final String BAR_TEST_CLASS = "BarTest"; - @Test - public void defaultOptions() { - PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); - assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode()); - assertTrue(selector.isPitRunInParallel()); - assertFalse(selector.isIncrementalAnalysisEnabled()); - assertEquals("The 'Excluded Classes' preference has not the expected value", - "*Test", selector.getExcludedClasses()); - assertTrue(selector.getExcludedMethods().isEmpty()); - assertThat(selector.getAvoidCallsTo(), equalTo(DEFAULT_AVOID_CALLS_TO_LIST)); - assertThat(selector.getTimeout(), equalTo(3000)); - assertEquals(selector.getPitTimeoutFactor(), new BigDecimal(1.25)); - assertThat(selector.getMutators().toString(), equalTo(DEFAULT_MUTATORS)); - selector.close(); - } - - @Test - public void useStrongerMutators() throws CoreException { + @BeforeClass + public static void setupJavaProject() { createJavaProjectWithJUnit4(TEST_PROJECT); verifyProjectExists(TEST_PROJECT); createClassWithMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT, @@ -80,6 +65,26 @@ public void useStrongerMutators() throws CoreException { + " " + BAR_CLASS + " x = new " + BAR_CLASS + "();\n" + " x.f(1);\n" + "}"); + } + + @Test + public void defaultOptions() { + PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); + assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode()); + assertTrue(selector.isPitRunInParallel()); + assertFalse(selector.isIncrementalAnalysisEnabled()); + assertEquals("The 'Excluded Classes' preference has not the expected value", + "*Test", selector.getExcludedClasses()); + assertTrue(selector.getExcludedMethods().isEmpty()); + assertThat(selector.getAvoidCallsTo(), equalTo(DEFAULT_AVOID_CALLS_TO_LIST)); + assertThat(selector.getTimeout(), equalTo(3000)); + assertEquals(selector.getPitTimeoutFactor(), new BigDecimal(1.25)); + assertThat(selector.getMutators().toString(), equalTo(DEFAULT_MUTATORS)); + selector.close(); + } + + @Test + public void useDefaultMutators() throws CoreException { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 80, 0); mutationsAre( @@ -89,7 +94,10 @@ public void useStrongerMutators() throws CoreException { "NO_COVERAGE | project1 | foo.bar | foo.bar.Bar | 8 | replaced int return with 0 for foo/bar/Bar::f\n" + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + "NO_COVERAGE | project1 | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); + } + @Test + public void useStrongerMutators() throws CoreException { // now set STRONGER mutators PAGES.getWindowsMenu().setMutators(STRONGER); try { From 16a90255758c58130e47636e1a2b1066acfab1ff Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 11:39:38 +0200 Subject: [PATCH 62/82] 81: started to test launch configurations Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../ui/behaviours/steps/PitclipseSteps.java | 7 ++++++- .../ui/tests/AbstractPitclipseSWTBotTest.java | 21 +++++++++++++++++++ .../ui/tests/PitclipseOptionsTest.java | 15 +++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java index 77ab1693..7af26efe 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PitclipseSteps.java @@ -138,7 +138,12 @@ public void runtimeOptionsMatch(DataTable configTable) { assertThat(configTable.height(), is(greaterThan(0))); assertThat(options, match(configTable.asMaps().get(0))); } - + + public void runtimeOptionsMatch(Map configMap) { + PitOptions options = PAGES.getRunMenu().getLastUsedPitOptions(); + assertThat(options, match(configMap)); + } + private void runPit(Runnable runnable) { assertNoErrorsInWorkspace(); // make sure to clear the console to avoid interferences diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 9116a9e4..4f932bb6 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -25,7 +25,9 @@ import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -331,4 +333,23 @@ protected static void coverageReportGenerated(int classes, double totalCoverage, new PitclipseSteps().coverageReportGenerated(classes, totalCoverage, mutationCoverage); } + protected static void runtimeOptionsMatch(String configTable) { + new PitclipseSteps().runtimeOptionsMatch(fromTableToMap(configTable)); + } + + protected static Map fromTableToMap(String table) { + Map map = new HashMap<>(); + String[] lines = table.split("\n"); + assertThat("You must specify a row with keys and a row with values", + lines.length, equalTo(2)); + String[] keyRow = lines[0].split("\\|"); + String[] valueRow = lines[1].split("\\|"); + assertThat("Keys and values do not match in number", + keyRow.length, equalTo(valueRow.length)); + for (int i = 0; i < keyRow.length; ++i) { + map.put(keyRow[i].trim(), valueRow[i].trim()); + } + return map; + } + } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index ddd916e7..3fc9d4e0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -117,4 +117,19 @@ public void useStrongerMutators() throws CoreException { PAGES.getWindowsMenu().setMutators(PitMutators.DEFAULTS); } } + + @Test + public void launchConfigurationsWithDefaultOptions() throws CoreException { + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 40, 0); +// runtimeOptionsMatch( +// "classUnderTest | classesToMutate | excludedClasses | excludedMethods | runInParallel | incrementalAnalysis | avoidCallsTo \n" + +// "foo.bar.FooTest | [foo.bar.BarTest, foo.bar.Foo, foo.bar.Bar, foo.bar.FooTest] | [*Test] | | true | false | [java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j]" +// ); + runtimeOptionsMatch( + "classUnderTest \n" + + "foo.bar.FooTest " + ); + } + } From 2e600b89e68e3471155c97ca1ec8f2cf4716d15d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 12:55:55 +0200 Subject: [PATCH 63/82] 81: test default launch configurations Task-Url: http://github.com/pitest/pitclipse/issues/81 --- .../pitest/pitclipse/ui/tests/PitclipseOptionsTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 3fc9d4e0..5c10aa77 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -122,13 +122,9 @@ public void useStrongerMutators() throws CoreException { public void launchConfigurationsWithDefaultOptions() throws CoreException { runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 40, 0); -// runtimeOptionsMatch( -// "classUnderTest | classesToMutate | excludedClasses | excludedMethods | runInParallel | incrementalAnalysis | avoidCallsTo \n" + -// "foo.bar.FooTest | [foo.bar.BarTest, foo.bar.Foo, foo.bar.Bar, foo.bar.FooTest] | [*Test] | | true | false | [java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j]" -// ); runtimeOptionsMatch( - "classUnderTest \n" + - "foo.bar.FooTest " + "classUnderTest | classesToMutate | excludedClasses | excludedMethods | runInParallel | incrementalAnalysis | avoidCallsTo \n" + + "foo.bar.FooTest | foo.bar.BarTest, foo.bar.Foo, foo.bar.Bar, foo.bar.FooTest | *Test | | true | false | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j" ); } From 6bf3b0cae9f4015405ad8d00de82c025655cbe0d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 13:55:04 +0200 Subject: [PATCH 64/82] removed exported service package --- bundles/org.pitest.pitclipse.runner/META-INF/MANIFEST.MF | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundles/org.pitest.pitclipse.runner/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.runner/META-INF/MANIFEST.MF index afa39a20..8e1f0e88 100644 --- a/bundles/org.pitest.pitclipse.runner/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.runner/META-INF/MANIFEST.MF @@ -15,8 +15,7 @@ Export-Package: org.pitest.pitclipse.runner, org.pitest.pitclipse.runner.results, org.pitest.pitclipse.runner.results.mutations, org.pitest.pitclipse.runner.results.summary, - org.pitest.pitclipse.runner.server, - org.pitest.pitclipse.runner.service + org.pitest.pitclipse.runner.server Import-Package: com.google.common.annotations;version="21.0.0", com.google.common.base;version="21.0.0", com.google.common.collect;version="21.0.0", From 27a74870651cb02f7b92ceb36442dccb0e2da250 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 15:31:58 +0200 Subject: [PATCH 65/82] 81: test run options and launch configurations Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../META-INF/MANIFEST.MF | 1 + .../META-INF/MANIFEST.MF | 3 +- .../steps/LaunchConfigurationSteps.java | 2 +- .../ui/tests/AbstractPitclipseSWTBotTest.java | 47 ++++++++++++++++++- .../ui/tests/PitclipseOptionsTest.java | 17 +++++++ 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF index 7cacd130..38e7c3e2 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF @@ -18,3 +18,4 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.1,4.0.0)", org.eclipse.ui.workbench;bundle-version="[3.107.1,4.0.0)", org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)" Import-Package: com.google.common.collect;version="21.0.0" +Export-Package: org.pitest.pitclipse.launch.ui diff --git a/tests/org.pitest.pitclipse.ui.tests/META-INF/MANIFEST.MF b/tests/org.pitest.pitclipse.ui.tests/META-INF/MANIFEST.MF index 16654ce5..3e396c0b 100644 --- a/tests/org.pitest.pitclipse.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.pitest.pitclipse.ui.tests/META-INF/MANIFEST.MF @@ -24,4 +24,5 @@ Require-Bundle: org.eclipse.swtbot.eclipse.finder, org.pitest.pitclipse.launch;bundle-version="2.0.0", org.pitest.pitclipse.launch.ui;bundle-version="2.0.0", org.pitest.pitclipse.preferences.ui;bundle-version="2.0.0", - io.cucumber;bundle-version="4.3.0" + io.cucumber;bundle-version="4.3.0", + org.eclipse.debug.core diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/LaunchConfigurationSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/LaunchConfigurationSteps.java index 96130ac8..531ad49f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/LaunchConfigurationSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/LaunchConfigurationSteps.java @@ -103,7 +103,7 @@ public void launchConfigurationsMatch(DataTable configTable) { configurationsMatch(configTable.asMaps(), launchConfigurations); } - private void configurationsMatch(List> expectedRows, List launchConfigurations) { + public void configurationsMatch(List> expectedRows, List launchConfigurations) { launchConfigurations = new ArrayList<>(launchConfigurations); launchConfigurations.removeIf(conf -> conf.getName().contains("(")); assertEquals("The number of existing configurations is not the expected one", expectedRows.size(), launchConfigurations.size()); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 4f932bb6..4215dda9 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; @@ -32,6 +33,10 @@ import java.util.stream.Stream; import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; @@ -46,7 +51,10 @@ import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.launch.ui.PitLaunchShortcut; import org.pitest.pitclipse.runner.results.DetectionStatus; +import org.pitest.pitclipse.ui.behaviours.pageobjects.PitRunConfiguration; +import org.pitest.pitclipse.ui.behaviours.steps.LaunchConfigurationSteps; import org.pitest.pitclipse.ui.behaviours.steps.PitMutation; import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps; @@ -334,10 +342,10 @@ protected static void coverageReportGenerated(int classes, double totalCoverage, } protected static void runtimeOptionsMatch(String configTable) { - new PitclipseSteps().runtimeOptionsMatch(fromTableToMap(configTable)); + new PitclipseSteps().runtimeOptionsMatch(fromTwoRowTableToMap(configTable)); } - protected static Map fromTableToMap(String table) { + protected static Map fromTwoRowTableToMap(String table) { Map map = new HashMap<>(); String[] lines = table.split("\n"); assertThat("You must specify a row with keys and a row with values", @@ -352,4 +360,39 @@ protected static Map fromTableToMap(String table) { return map; } + protected static void launchConfigurationsMatch(String configTable) { + List launchConfigurations = PAGES.getRunMenu().runConfigurations(); + new LaunchConfigurationSteps().configurationsMatch + (fromTableToMap(configTable), launchConfigurations); + } + + protected static List> fromTableToMap(String table) { + List> maps = new ArrayList<>(); + String[] lines = table.split("\n"); + assertThat("You must specify at least a row with keys and rows with values", + lines.length, greaterThanOrEqualTo(2)); + String[] keyRow = lines[0].split("\\|"); + for (int i = 1; i < lines.length; ++i) { + Map map = new HashMap<>(); + maps.add(map); + String[] valueRow = lines[i].split("\\|"); + assertThat("Keys and values do not match in number", + keyRow.length, equalTo(valueRow.length)); + for (int j = 0; j < keyRow.length; ++j) { + map.put(keyRow[j].trim(), valueRow[j].trim()); + } + } + return maps; + } + + protected static void removePitLaunchConfigurations() throws CoreException { + ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfigurationType type = + manager.getLaunchConfigurationType(PitLaunchShortcut.PIT_CONFIGURATION_TYPE); + ILaunchConfiguration[] lcs = manager.getLaunchConfigurations(type); + for (ILaunchConfiguration launchConfiguration : lcs) { + launchConfiguration.delete(); + } + } + } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 5c10aa77..91e68165 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -67,6 +68,11 @@ public static void setupJavaProject() { + "}"); } + @Before + public void removeLaunchConfigurations() throws CoreException { + removePitLaunchConfigurations(); + } + @Test public void defaultOptions() { PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); @@ -126,6 +132,17 @@ public void launchConfigurationsWithDefaultOptions() throws CoreException { "classUnderTest | classesToMutate | excludedClasses | excludedMethods | runInParallel | incrementalAnalysis | avoidCallsTo \n" + "foo.bar.FooTest | foo.bar.BarTest, foo.bar.Foo, foo.bar.Bar, foo.bar.FooTest | *Test | | true | false | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j" ); + launchConfigurationsMatch( + "name | runInParallel | useIncrementalAnalysis | excludedClasses | excludedMethods | avoidCallsTo \n" + + "FooTest | true | false | *Test | | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j" + ); + runTest(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 40, 0); + launchConfigurationsMatch( + "name | runInParallel | useIncrementalAnalysis | excludedClasses | excludedMethods | avoidCallsTo \n" + + "BarTest | true | false | *Test | | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j |\n" + + "FooTest | true | false | *Test | | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j" + ); } } From 9b9ea392c5e114039494b122a6a006b117d17dbb Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 15:38:59 +0200 Subject: [PATCH 66/82] 81: documented assertion methods Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/AbstractPitclipseSWTBotTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 4215dda9..8e798dbc 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -341,6 +341,19 @@ protected static void coverageReportGenerated(int classes, double totalCoverage, new PitclipseSteps().coverageReportGenerated(classes, totalCoverage, mutationCoverage); } + /** + * The configTable String argument represents the expected + * runtime options, a two row table is expected with the same number + * of columns; the first row contains the keys and the second row contains the values. + * Example (the alignment is optional and spaces are trimmed): + * + *
+     * "classUnderTest  | classesToMutate              | excludedClasses | excludedMethods | runInParallel | incrementalAnalysis | avoidCallsTo                                                               \n" +
+     * "foo.bar.FooTest | foo.bar.BarTest, foo.bar.Foo | *Test           |                 | true          | false               | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j"
+     * 
+ * + * @param configTable + */ protected static void runtimeOptionsMatch(String configTable) { new PitclipseSteps().runtimeOptionsMatch(fromTwoRowTableToMap(configTable)); } @@ -360,6 +373,20 @@ protected static Map fromTwoRowTableToMap(String table) { return map; } + /** + * The configTable String argument represents the expected + * launch configurations elements, a table with at least two rows is expected with the same number + * of columns; the first row contains the keys and other ones contain the values. + * Example (the alignment is optional and spaces are trimmed): + * + *
+     *   "name    | runInParallel | useIncrementalAnalysis | excludedClasses | excludedMethods | avoidCallsTo                                                               \n"
+     * + "BarTest | true          | false                  | *Test           |                 | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j \n"
+     * + "FooTest | true          | false                  | *Test           |                 | java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j"
+     * 
+ * + * @param configTable + */ protected static void launchConfigurationsMatch(String configTable) { List launchConfigurations = PAGES.getRunMenu().runConfigurations(); new LaunchConfigurationSteps().configurationsMatch From ef014fffa339d94dfa06e825db8a0078cf002777 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 15:47:35 +0200 Subject: [PATCH 67/82] 81: use constants to check default options Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../pitest/pitclipse/ui/tests/PitclipseOptionsTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 91e68165..126e325e 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -11,8 +11,6 @@ import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; -import java.math.BigDecimal; - import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.Before; @@ -20,6 +18,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.pitest.pitclipse.core.PitMutators; +import org.pitest.pitclipse.runner.config.PitConfiguration; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitPreferenceSelector; /** @@ -83,8 +82,8 @@ public void defaultOptions() { "*Test", selector.getExcludedClasses()); assertTrue(selector.getExcludedMethods().isEmpty()); assertThat(selector.getAvoidCallsTo(), equalTo(DEFAULT_AVOID_CALLS_TO_LIST)); - assertThat(selector.getTimeout(), equalTo(3000)); - assertEquals(selector.getPitTimeoutFactor(), new BigDecimal(1.25)); + assertThat(selector.getTimeout(), equalTo(PitConfiguration.DEFAULT_TIMEOUT)); + assertThat(selector.getPitTimeoutFactor(), equalTo(PitConfiguration.DEFAULT_TIMEOUT_FACTOR)); assertThat(selector.getMutators().toString(), equalTo(DEFAULT_MUTATORS)); selector.close(); } From f0a56ea9b6f70a58ad2d599c2530cb51dba3efc5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 16:04:17 +0200 Subject: [PATCH 68/82] 81: tests runtime options with changed preferences Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../ui/tests/PitclipseOptionsTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 126e325e..ba11b553 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -12,12 +12,15 @@ import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.PitMutators; +import org.pitest.pitclipse.core.preferences.PitPreferences; import org.pitest.pitclipse.runner.config.PitConfiguration; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitPreferenceSelector; @@ -144,4 +147,29 @@ public void launchConfigurationsWithDefaultOptions() throws CoreException { ); } + @Test + public void launchConfigurationsWithChangedValues() throws CoreException { + try { + PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); + selector.setPitTimeoutConst(2000); + selector.setPitTimeoutFactor(2); + selector.setPitRunInParallel(false); + selector.setPitIncrementalAnalysisEnabled(true); + selector.close(); + runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 40, 0); + runtimeOptionsMatch( + "classUnderTest | timeoutConst | timeoutFactor | runInParallel | incrementalAnalysis \n" + + "foo.bar.FooTest | 2000 | 2 | false | true " + ); + } finally { + // reset default values + IPreferenceStore preferenceStore = PitCoreActivator.getDefault().getPreferenceStore(); + preferenceStore.setValue(PitPreferences.TIMEOUT, PitConfiguration.DEFAULT_TIMEOUT); + preferenceStore.setValue(PitPreferences.TIMEOUT_FACTOR, PitConfiguration.DEFAULT_TIMEOUT_FACTOR.toString()); + preferenceStore.setValue(PitPreferences.RUN_IN_PARALLEL, true); + preferenceStore.setValue(PitPreferences.INCREMENTAL_ANALYSIS, false); + } + } + } From 0894432cc87b337663cfeaf65e0dbefd9eaa5dc0 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 16:10:22 +0200 Subject: [PATCH 69/82] 81: test with custom excluded classes Task-Url: https://github.com/pitest/pitclipse/issues/81 --- .../pitclipse/core/preferences/PreferenceInitializer.java | 3 ++- .../pitest/pitclipse/runner/config/PitConfiguration.java | 1 + .../org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java index 892d6476..8681404d 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.runner.config.PitConfiguration; import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; @@ -53,7 +54,7 @@ public void initializeDefaultPreferences() { store.setDefault(DEFAULT_MUTATORS, "defaultMutators"); store.setDefault(TIMEOUT, DEFAULT_TIMEOUT); store.setDefault(TIMEOUT_FACTOR, DEFAULT_TIMEOUT_FACTOR.toString()); - store.setDefault(EXCLUDED_CLASSES, "*Test"); + store.setDefault(EXCLUDED_CLASSES, PitConfiguration.DEFAULT_EXCLUDED_CLASSES); } } diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java index 29aa006f..b9a4ec67 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java @@ -23,6 +23,7 @@ public class PitConfiguration { public static final String DEFAULT_AVOID_CALLS_TO_LIST = "java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j"; public static final String DEFAULT_MUTATORS = "DEFAULTS"; + public static final String DEFAULT_EXCLUDED_CLASSES = "*Test"; public static final int DEFAULT_TIMEOUT = 3000; public static final BigDecimal DEFAULT_TIMEOUT_FACTOR = BigDecimal.valueOf(1.25); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index ba11b553..21544dd0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -155,12 +155,13 @@ public void launchConfigurationsWithChangedValues() throws CoreException { selector.setPitTimeoutFactor(2); selector.setPitRunInParallel(false); selector.setPitIncrementalAnalysisEnabled(true); + selector.setExcludedClasses("org.foo.*IntTest, *DbTest"); selector.close(); runTest(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 40, 0); runtimeOptionsMatch( - "classUnderTest | timeoutConst | timeoutFactor | runInParallel | incrementalAnalysis \n" + - "foo.bar.FooTest | 2000 | 2 | false | true " + "classUnderTest | timeoutConst | timeoutFactor | runInParallel | incrementalAnalysis | excludedClasses \n" + + "foo.bar.FooTest | 2000 | 2 | false | true | org.foo.*IntTest, *DbTest" ); } finally { // reset default values @@ -169,6 +170,7 @@ public void launchConfigurationsWithChangedValues() throws CoreException { preferenceStore.setValue(PitPreferences.TIMEOUT_FACTOR, PitConfiguration.DEFAULT_TIMEOUT_FACTOR.toString()); preferenceStore.setValue(PitPreferences.RUN_IN_PARALLEL, true); preferenceStore.setValue(PitPreferences.INCREMENTAL_ANALYSIS, false); + preferenceStore.setValue(PitPreferences.EXCLUDED_CLASSES, PitConfiguration.DEFAULT_EXCLUDED_CLASSES); } } From 4eb974511907ef76619b02c2e826a625f3a118c7 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 13 May 2021 16:16:03 +0200 Subject: [PATCH 70/82] 81: further increased swtbot timeout Task-Url: https://github.com/pitest/pitclipse/issues/81 --- tests/org.pitest.pitclipse.ui.tests/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/pom.xml b/tests/org.pitest.pitclipse.ui.tests/pom.xml index 704f91e0..bad40d9f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/pom.xml +++ b/tests/org.pitest.pitclipse.ui.tests/pom.xml @@ -86,7 +86,8 @@ true false true - ${additionalTestArgLine} ${os-jvm-flags} -Dorg.eclipse.swtbot.search.timeout=20000 + + ${additionalTestArgLine} ${os-jvm-flags} -Dorg.eclipse.swtbot.search.timeout=50000 - ${additionalTestArgLine} ${os-jvm-flags} -Dorg.eclipse.swtbot.search.timeout=50000 + ${additionalTestArgLine} ${os-jvm-flags} -Dorg.eclipse.swtbot.search.timeout=60000 From 3776d201f3487fadd1499d0cbc2c85b2895f6dd3 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 10 Jul 2021 13:35:15 +0200 Subject: [PATCH 82/82] don't exclude sonar code coverage on UI classes --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index 9e2ed181..a8d2ad36 100644 --- a/pom.xml +++ b/pom.xml @@ -59,11 +59,6 @@ **/*Exception.java, **/*Activator.java - - - **/ui/**/*.java - ${basedir}/../../tests/org.pitest.pitclipse.tests.coverage.report/target/site/jacoco-aggregate/jacoco.xml