Skip to content

Commit

Permalink
205: test run as when editor is focused
Browse files Browse the repository at this point in the history
Task-Url: #205
  • Loading branch information
LorenzoBettini committed Aug 25, 2022
1 parent b7122ba commit 5184f4a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ public SWTBotTreeItem selectPackageRoot(String projectName, String src) {

}

public void selectProjectFile(String projectName, String fileName) {
SWTBotTreeItem project = getProject(projectName);
project.select(fileName);
public SWTBotTreeItem selectProjectFile(String projectName, String fileName) {
SWTBotTreeItem project = getProject(projectName).expand();
// REMEMBER: first get the node and then selectAndExpand
SWTBotTreeItem fileItem = project.getNode(fileName);
return selectAndExpand(fileItem);
}

public void selectProjectElement(String... path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public void runJUnit() {
}

public void runPit() {
// focusing on package explorer does not allow to run PIT
// when an editor is selected, and it should not be needed at all anyway
// focus package explorer to ensure the menu is found
bot.viewByTitle("Package Explorer").setFocus();
// bot.viewByTitle("Package Explorer").setFocus();
SWTBotMenuHelper menuHelper = new SWTBotMenuHelper();
SWTBotMenu runAsMenu = menuHelper.findWorkbenchMenu(bot, RUN).menu(RUN_AS);
menuHelper.findMenu(runAsMenu, PIT_MUTATION_TEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,17 @@ private static String indent(String contents) {
.collect(Collectors.joining("\n"));
}

/**
* The editor is expected to be already opened
*
* @param fileName
* @throws CoreException
*/
protected static void runFromEditorTest(final String fileName) throws CoreException {
new PitclipseSteps().runPitAndWaitForIt(() ->
bot.editorByTitle(fileName).setFocus());
}

protected static void runTest(final String testClassName, final String packageName, final String projectName) throws CoreException {
new PitclipseSteps().runTest(testClassName, packageName, projectName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,33 @@ class MyException extends RuntimeException {
// OK
}
}

@Test
public void runPitFromEditor() throws CoreException {
createMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT,
"public int doFoo(int i) {\n"
+ " return i + 1;\n"
+ "}");
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"
+ "}");
runFromEditorTest(FOO_TEST_CLASS + ".java");
mutationsAre(
"KILLED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 6 | Replaced integer addition with subtraction \n" +
"KILLED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 6 | replaced int return with 0 for foo/bar/Foo::doFoo ");
coverageReportGenerated(1, 100, 100, 2, 2);
}

@Test
public void runPitFromEditorOnNonJavaFile() throws CoreException {
PAGES.getPackageExplorer()
.selectProjectFile(TEST_PROJECT, "README")
.doubleClick();
PAGES.getRunMenu().runPit();
new NoTestsFoundDialog(bot).assertAppears();
}

}

0 comments on commit 5184f4a

Please sign in to comment.