Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
HelpWindowTest: fix failing test in non-headless mode (#880)
Browse files Browse the repository at this point in the history
HelpWindowTest#focus_helpWindowNotFocused_focused() test checks that
the HelpWindow#focus() method will cause the HelpWindow to be in focus
when called. The test first asserts that the HelpWindow is not in focus
first after it is shown, being calling this method and asserting that
the HelpWindow is now in focus.

When tests are run in non-headless mode, the HelpWindow will be in
focus immediately after it is shown, thus our first assertion is
incorrect, causing the test to consistently fail in non-headless mode.

Let's add a method GuiRobot#removeFocus(), and update the test to call
this method to remove focus from the HelpWindow after it is shown
to ensure the first assertion is correct in non-headless mode.

  [1/3] HelpWindowTest: fix failing test in non-headless mode
  [2/3] HelpWindowTest: skip test with buggy behavior in headless mode
  [3/3] build.gradle: enable logging of skipped tests
  • Loading branch information
pyokagan authored Apr 24, 2018
2 parents e968a29 + fc69d10 commit 8d2322b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
16 changes: 10 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/guitests/GuiRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/seedu/address/ui/HelpWindowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,8 +47,12 @@ public void isShowing_helpWindowIsHiding_returnsFalse() {
}

@Test
public void focus_helpWindowNotFocused_focused() {
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
FxToolkit.setupStage(Stage::requestFocus);
assertFalse(helpWindow.getRoot().isFocused());

guiRobot.interact(helpWindow::focus);
Expand Down

0 comments on commit 8d2322b

Please sign in to comment.