I'd like to put together a set of jUnit tests under Eclipse (Neon) on Windows to automate the testing of JavaFX GUIs. It seems that TestFX is the bee's knees for this kind of thing, but having looked around the internet quite a bit, I'm still not sure how to install TestFX without using Maven or Gradle.
I am not familiar with Maven and Gradle, and trying to follow the simple instructions to install TestFX via Maven was unsuccessful. This was done under Eclipse Mars, after which my simple GUI program threw up a compile error about not being able to find or load main class and a run-time error that Selection does not contain a main type. (The simple GUI program ran without errors previously.) After this, I downloaded the latest Eclipse Neon and tried to start afresh.
This is what I did:
- Download and install Eclipse Neon from eclipse.org.
- Create a Java Project called TestProject (execution environment JavaSE-1.8).
- Grant access to
javafx/**
(right-click on project -- properties -- Java Build Path -- Libraries -- JRE System Library -- Access Rules -- add). - Create MyClass with minimal contents:
package test; import javafx.application.Application; import javafx.stage.Stage; public class MyClass extends Application { @Override public void start(Stage stage) throws Exception { stage.setTitle("Hello World"); stage.show(); } }
- Copy the file
testfx-core-4.0.0-20150226.214553-8.jar
from the testfx repository (linked from the Via direct download section of How to use TestFX in your project) into my eclipse project, sitting at the same level as the JRE System Library; - Add the jar file to the build path (right-click on project -- properties -- Java Build Path -- Libraries -- Add JARS) - this automatically created a directory called Referenced Libraries and copied the jar file into it; and
- Create a JUnit test (right-click on source folder -- New -- JUnit Test Case), filling in the appropriate package and Class under test fields, and giving the test case a name (MyTest).
Then I tried to extend the class MyTest to use testfx:
class MyTest extends GuiTest {}
as advised in this link; and (separately)class MyTest extends ApplicationTest{}
as advised in this link.
Here's the code in the second case:
package test; import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; public class MyTest extends ApplicationTest { }
In each case, eclipse complains that the superclass GuiTest
/ ApplicationTest
cannot be resolved to a type.
I suspect that the problem is that I haven't properly installed testfx. Can anyone help?