I was trying to use TestFX to test my application. I would like to run the test for the method of my controller.
Main.java:
public class Main extends Application {
    try{
        new Flow(ManageCtrl.class).startInStage(primaryStage);
    } catch (Exception ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    }
}
ManageCtrl.java:
@ViewController("/FPManage.fxml")
public class ManageCtrl extends AnchorPane {
    @FXML // fx:id="email"
    private TextField email; // Value injected by FXMLLoader
    public void setEmail(String address) {
        this.email.setText(address);
    }
}
ManageCtrlTest.java:
public class ManageCtrlTest extends ApplicationTest {
    @Override
    public void start(Stage stage) {
        try {
            new Flow(ManageCtrl.class).startInStage(stage);
        } catch (FlowException ex) {
            Logger.getLogger(ManageCtrlTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    @Test
    public void testSetEmail() {
        ManageCtrl instance = new ManageCtrl();
        instance.setEmail("test@gmai.com");
        assertEquals("test@gmail.com", ((TextField)GuiTest.find("#email")).getText());
    }
}
But I get the following Exception:
testSetEmail Failed: java.lang.illegalStateException: Not on FX application thread; currentThread = Test worker
java.lang.illegalStateException: Not on FX application thread; currentThread = Test Worker
Thanks for the help.
. Also failed to add high light syntax. – chiahao Mar 12 '15 at 03:30