From 1c6071fa439f23f3aa1ce378b5788c73682162a0 Mon Sep 17 00:00:00 2001 From: Jun An Date: Mon, 16 Apr 2018 18:17:58 +0800 Subject: [PATCH 1/3] HelpWindowTest: fix failing test in non-headless mode HelpWindowTest#focus_helpWindowNotFocused_focused() asserts that the HelpWindow is not in focus when it is first shown, and then asserts that the HelpWindow comes into focus after calling HelpWindow#focus(). When tests are run in non-headless mode, the HelpWindow will be in focus when it is first shown, thus rendering our first assumption false and causing the test to fail. Let's update the test to focus on another TestFx Stage, which will remove focus from the HelpWindow when it is first shown, ensuring that the initial assumption is true. --- src/test/java/seedu/address/ui/HelpWindowTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/ui/HelpWindowTest.java b/src/test/java/seedu/address/ui/HelpWindowTest.java index 461f5bba2eae..4fcb1fcfb9f7 100644 --- a/src/test/java/seedu/address/ui/HelpWindowTest.java +++ b/src/test/java/seedu/address/ui/HelpWindowTest.java @@ -46,8 +46,11 @@ public void isShowing_helpWindowIsHiding_returnsFalse() { } @Test - public void focus_helpWindowNotFocused_focused() { + public void focus_helpWindowNotFocused_focused() throws Exception { guiRobot.interact(helpWindow::show); + + // Focus on another stage to remove focus from the helpWindow + FxToolkit.setupStage(Stage::requestFocus); assertFalse(helpWindow.getRoot().isFocused()); guiRobot.interact(helpWindow::focus); From 2cf5b9816afa83977b2b4452cbe8b5076dde1d3e Mon Sep 17 00:00:00 2001 From: Jun An Date: Sat, 21 Apr 2018 17:52:00 +0800 Subject: [PATCH 2/3] HelpWindowTest: skip test with buggy behavior in headless mode HelpWindowTest#focus_helpWindowNotFocused_focused test checks whether calling HelpWindow#focus() will bring the HelpWindow to focus. Normally, when HelpWindow#show() is called, the HelpWindow's Stage should automatically be in focus. However, when tests are run in headless mode, the HelpWindow in HelpWindowTest#focus_helpWindowNotFocused_focused test does not automatically come into focus after it is shown. This is due to HelpWindowStage in setUp() setting the HelpWindow's Scene to itself. According to the JavaFx docs for Window#setScene(Scene)[1], a Scene can only be on one Stage at a time, and setting a Scene on a different Stage will cause the old Stage to lose the reference. As a result, the HelpWindow's Stage will not have a reference to any Scene, resulting in the HelpWindow's Stage not coming into focus automatically, due to a bug with Monocle's headless mode. Let's skip HelpWindowTest#focus_helpWindowNotFocused_focused test when tests are run in headless mode as it is relying on buggy behavior. [1]: JavaFx docs for Window#setScene(Scene): https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Window.html#setScene-javafx.scene.Scene- --- src/test/java/guitests/GuiRobot.java | 7 +++++++ src/test/java/seedu/address/ui/HelpWindowTest.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/test/java/guitests/GuiRobot.java b/src/test/java/guitests/GuiRobot.java index d8a301aa41e7..f4e0700b22f7 100644 --- a/src/test/java/guitests/GuiRobot.java +++ b/src/test/java/guitests/GuiRobot.java @@ -39,6 +39,13 @@ public void pauseForHuman() { sleep(PAUSE_FOR_HUMAN_DELAY_MILLISECONDS); } + /** + * Returns true if tests are run in headless mode. + */ + public boolean isHeadlessMode() { + return isHeadlessMode; + } + /** * Waits for {@code event} to be true by {@code DEFAULT_WAIT_FOR_EVENT_TIMEOUT_MILLISECONDS} milliseconds. * diff --git a/src/test/java/seedu/address/ui/HelpWindowTest.java b/src/test/java/seedu/address/ui/HelpWindowTest.java index 4fcb1fcfb9f7..0dfb9842284c 100644 --- a/src/test/java/seedu/address/ui/HelpWindowTest.java +++ b/src/test/java/seedu/address/ui/HelpWindowTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; import static seedu.address.ui.HelpWindow.USERGUIDE_FILE_PATH; import java.net.URL; @@ -47,6 +48,7 @@ public void isShowing_helpWindowIsHiding_returnsFalse() { @Test public void focus_helpWindowNotFocused_focused() throws Exception { + assumeFalse("Test skipped in headless mode: Window focus behavior is buggy.", guiRobot.isHeadlessMode()); guiRobot.interact(helpWindow::show); // Focus on another stage to remove focus from the helpWindow From fc69d109980a26e9ede441c84b986ee530107073 Mon Sep 17 00:00:00 2001 From: Jun An Date: Sat, 21 Apr 2018 17:59:30 +0800 Subject: [PATCH 3/3] build.gradle: enable logging of skipped tests Our build.gradle configuration does not log to the console tests that were skipped. These tests may have been skipped for certain reasons, e.g. they do not support headless mode and should be run in non-headless mode instead. As these tests that are skipped may actually be failing, we should enable logging of these tests so that users know which tests needs to be tested separately. Lets update build.gradle to enable logging of tests that were skipped. --- build.gradle | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 75a518ea61d8..5c0329e610ec 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,8 @@ // For more details take a look at the Java Quickstart chapter in the Gradle // user guide available at http://gradle.org/docs/4.6/userguide/tutorial_java_projects.html +import org.gradle.api.tasks.testing.logging.TestLogEvent + plugins { id 'java' id 'jacoco' @@ -117,12 +119,14 @@ allTests.dependsOn nonGuiTests test { systemProperty 'testfx.setup.timeout', '60000' - // Prints the currently running test's name in the CI's build log, - // so that we can check if tests are being silently skipped or - // stalling the build. - if (System.env.'CI') { - beforeTest { descriptor -> - logger.lifecycle("Running test: ${descriptor}") + testLogging { + events TestLogEvent.FAILED, TestLogEvent.SKIPPED + + // Prints the currently running test's name in the CI's build log, + // so that we can check if tests are being silently skipped or + // stalling the build. + if (System.env.'CI') { + events << TestLogEvent.STARTED } }