1 Reply Latest reply: May 22, 2013 12:39 PM by csh RSS

    How to box test JavaFx UI?

    likejiujitsu
      I have never box tested a UI and wondered how to (automated) box test my Java Fx 2.2 UI. Any recommendations?
      I found a link to Jemmy FX, and also Marvin. Anyone has experiences good/bad with either?
        • 1. Re: How to box test JavaFx UI?
          csh
          I'd also be interested in a solution for testing.

          I tried to do it like this, but the problem is, that Application.launch must only be called once.
          public class TestCase {
          
              @Test
              public void test1() {
                  Application.launch(TestClass1.class);
              }
          
              @Test
              public void test2() {
                  Application.launch(TestClass2.class);
              }
          
              public static class TestClass1 extends Application {
          
                  @Override
                  public void start(Stage stage) throws Exception {
                      TextField textField = new TextField();
                      textField.setText("test");
                      Assert.assertEquals(textField.getText(), "test");
                      Platform.exit();
                  }
              }
          
              public static class TestClass2 extends Application {
          
                  @Override
                  public void start(Stage stage) throws Exception {
                      Assert.fail();
                      Platform.exit();
                  }
              }
          }
          You could do all your test cases in one big start() method though. That's how I currently do it.

          Or something like this works too for small tests:
          public class TestCase extends Application {
          
              @BeforeClass
              public void setup() {
                  Application.launch();
              }
          
              @Test
              public void test1() {
                  TextField textField = new TextField();
                  textField.setText("test");
                  Assert.assertEquals(textField.getText(), "test");
              }
          
              @Test
              public void test2() {
                  TextField textField = new TextField();
                  textField.setText("test");
                  Assert.assertEquals(textField.getText(), "test");
              }
          
              @Override
              public void start(Stage stage) throws Exception {
                  Platform.exit();
              }
          }