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

Commit

Permalink
[#684] Guitests: Move tests to other packages (#692)
Browse files Browse the repository at this point in the history
AddressBookGuiTest and AddressBookSystemTest are very similar.

It’s not necessary to have both of them.

Let's remove AddressBookGuiTest by shifting out the children classes to
inherit from AddressBookSystemTest instead.
  • Loading branch information
Zhiyuan-Amos authored Sep 28, 2017
2 parents 74354ad + bb6fd97 commit e7db399
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 201 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class AddressBookTest extends Test {
}

task guiTests(type: AddressBookTest) {
include 'guitests/**'
include 'systemtests/**'
include 'seedu/address/ui/**'

Expand Down
2 changes: 1 addition & 1 deletion docs/UsingGradle.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The set of code style rules implemented can be found in `config/checkstyle/check
* **`allTests`** +
Runs all tests.
* **`guiTests`** +
Runs all tests in the `guitests` package
Runs all tests in the `seedu.address.ui` and `systemtests` package
* **`nonGuiTests`** +
Runs all non-GUI tests in the `seedu.address`
package
Expand Down
115 changes: 0 additions & 115 deletions src/test/java/guitests/AddressBookGuiTest.java

This file was deleted.

69 changes: 0 additions & 69 deletions src/test/java/guitests/StatusBarFooterTest.java

This file was deleted.

22 changes: 21 additions & 1 deletion src/test/java/systemtests/AddressBookSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.testutil.TypicalPersons;
import seedu.address.ui.CommandBox;

/**
Expand All @@ -64,7 +66,7 @@ public static void setupBeforeClass() {
@Before
public void setUp() {
setupHelper = new SystemTestSetupHelper();
testApp = setupHelper.setupApplication();
testApp = setupHelper.setupApplication(this::getInitialData, getDataFileLocation());
mainWindowHandle = setupHelper.setupMainWindowHandle();

waitUntilBrowserLoaded(getBrowserPanel());
Expand All @@ -77,6 +79,24 @@ public void tearDown() throws Exception {
EventsCenter.clearSubscribers();
}

/**
* Returns the data to be loaded into the file in {@link #getDataFileLocation()}.
*/
protected AddressBook getInitialData() {
return TypicalPersons.getTypicalAddressBook();
}

/**
* Returns the directory of the data file.
*/
protected String getDataFileLocation() {
return TestApp.SAVE_LOCATION_FOR_TESTING;
}

public MainWindowHandle getMainWindowHandle() {
return mainWindowHandle;
}

public CommandBoxHandle getCommandBox() {
return mainWindowHandle.getCommandBox();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package guitests;
package systemtests;

import static org.junit.Assert.assertEquals;
import static seedu.address.testutil.EventsUtil.postLater;
Expand All @@ -10,12 +10,14 @@

import org.junit.Test;

import guitests.GuiRobot;
import guitests.guihandles.AlertDialogHandle;
import seedu.address.commons.events.storage.DataSavingExceptionEvent;

public class ErrorDialogGuiTest extends AddressBookGuiTest {
public class ErrorDialogGuiTest extends AddressBookSystemTest {

private static final IOException IO_EXCEPTION_STUB = new IOException("Stub");
private final GuiRobot guiRobot = new GuiRobot();

@Test
public void showErrorDialogs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package guitests;
package systemtests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import guitests.GuiRobot;
import guitests.guihandles.HelpWindowHandle;
import seedu.address.logic.commands.HelpCommand;

public class HelpWindowTest extends AddressBookGuiTest {
/**
* TODO: This test is incomplete as it is missing test cases.
*/
public class HelpCommandSystemTest extends AddressBookSystemTest {
private static final String ERROR_MESSAGE = "ATTENTION!!!! : On some computers, this test may fail when run on "
+ "non-headless mode as FxRobot#clickOn(Node, MouseButton...) clicks on the wrong location. We suspect "
+ "that this is a bug with TestFX library that we are using. If this test fails, you have to run your "
+ "tests on headless mode. See UsingGradle.adoc on how to do so.";

private final GuiRobot guiRobot = new GuiRobot();

@Test
public void openHelpWindow() {
//use accelerator
Expand All @@ -38,7 +44,7 @@ public void openHelpWindow() {
assertHelpWindowOpen();

//use command box
runCommand(HelpCommand.COMMAND_WORD);
executeCommand(HelpCommand.COMMAND_WORD);
assertHelpWindowOpen();
}

Expand All @@ -50,7 +56,7 @@ private void assertHelpWindowOpen() {
guiRobot.pauseForHuman();

new HelpWindowHandle(guiRobot.getStage(HelpWindowHandle.HELP_WINDOW_TITLE)).close();
mainWindowHandle.focus();
getMainWindowHandle().focus();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package guitests;
package systemtests;

import static seedu.address.ui.testutil.GuiTestAssert.assertListMatching;

Expand All @@ -13,16 +13,20 @@
import seedu.address.model.util.SampleDataUtil;
import seedu.address.testutil.TestUtil;

public class SampleDataTest extends AddressBookGuiTest {
public class SampleDataTest extends AddressBookSystemTest {
/**
* Returns null to force test app to load data of the file in {@code getDataFileLocation()}.
*/
@Override
protected AddressBook getInitialData() {
// return null to force test app to load data from file only
return null;
}

/**
* Returns a non-existent file location to force test app to load sample data.
*/
@Override
protected String getDataFileLocation() {
// return a non-existent file location to force test app to load sample data
String filePath = TestUtil.getFilePathInSandboxFolder("SomeFileThatDoesNotExist1234567890.xml");
deleteFileIfExists(filePath);
return filePath;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/systemtests/SystemTestSetupHelper.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package systemtests;

import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;

import org.testfx.api.FxToolkit;

import guitests.guihandles.MainWindowHandle;
import seedu.address.TestApp;
import seedu.address.testutil.TypicalPersons;
import seedu.address.model.ReadOnlyAddressBook;

/**
* Contains helper methods that system tests require.
Expand All @@ -18,10 +19,9 @@ public class SystemTestSetupHelper {
/**
* Sets up the {@code TestApp} and returns it.
*/
public TestApp setupApplication() {
public TestApp setupApplication(Supplier<ReadOnlyAddressBook> addressBook, String saveFileLocation) {
try {
FxToolkit.setupApplication(() -> testApp = new TestApp(TypicalPersons::getTypicalAddressBook,
TestApp.SAVE_LOCATION_FOR_TESTING));
FxToolkit.setupApplication(() -> testApp = new TestApp(addressBook, saveFileLocation));
} catch (TimeoutException te) {
throw new AssertionError("Application takes too long to set up.");
}
Expand Down

0 comments on commit e7db399

Please sign in to comment.