title: JavaFX tests failing randomly
body: <p>I have a JUnit Test Class that looks like the following :</p>
  
  <pre><code>public class HelloWorldApplicationTest {
  
  private static TextArea mEditor = new HelloWorldApplication().getmEditor();
  
  @BeforeClass
  public static void initToolKit() throws InterruptedException {
  
      final CountDownLatch latch = new CountDownLatch(1);
      SwingUtilities.invokeLater(() -&gt; {
          new JFXPanel(); // initializes JavaFX environment
          latch.countDown();
      });
  
      // That's a pretty reasonable delay... Right?
      if (!latch.await(5L, TimeUnit.SECONDS))
          throw new ExceptionInInitializerError();
  
  }
  
  
  @Test
  public void testA(){
      mEditor.setText("111");
      assertTrue(mEditor.getText().equals("111"));
      mEditor.setText("qqq");
      assertTrue(mEditor.getText().equals("qqq"));
      mEditor.setText("eee");
      assertTrue(mEditor.getText().equals("eee"));
      mEditor.setText("aaa");
      assertTrue(mEditor.getText().equals("aaa"));
      mEditor.setText("aaa");
      assertTrue(mEditor.getText().equals("aaa"));
  }
  
  @Test
  public void testB(){
      mEditor.setText("222");
      assertTrue(mEditor.getText().equals("222"));
      mEditor.setText("222");
      assertTrue(mEditor.getText().equals("222"));
      mEditor.setText("222");
      assertTrue(mEditor.getText().equals("222"));
      mEditor.setText("111");
      assertTrue(mEditor.getText().equals("111"));
  }
  
  @Test
  public void testC(){
      mEditor.setText("333");
      assertTrue(mEditor.getText().equals("333"));
      mEditor.setText("333");
      assertTrue(mEditor.getText().equals("333"));
      mEditor.setText("TTT");
      assertTrue(mEditor.getText().equals("TTT"));
      mEditor.setText("333");
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If I remove <code>initToolkit</code> method, tests will pass in Linux / OSX , but fail in windows throwing :</p>
  
  <pre><code>java.lang.ExceptionInInitializerError: null
          at com.sun.glass.ui.Screen.getScreens(Screen.java:70)
          at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61)
          at com.sun.javafx.font.PrismFontFactory.getSystemFontSize(PrismFontFactory.java:1911)
  </code></pre>
  
  <p>Or , mEditor isn't a static variable.</p>
  
  <pre><code>java.lang.RuntimeException: Internal graphics not initialized yet
  at com.sun.glass.ui.Screen.getScreens(Screen.java:70)
  at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61)
  at com.sun.javafx.font.PrismFontFactory.getSystemFontSize(PrismFontFactory.java:1911)
  </code></pre>
  
  <p>(See : <a href="https://stackoverflow.com/questions/46026733/javafx-test-that-fails-in-windows-and-works-in-osx-and-linux">JavaFX Test That fails in Windows and works in OSX and Linux</a> )</p>
  
  <p>If I add <code>initToolkit</code> method, JavaFX environment get initialised, but tests start to fail randomly, and sometimes tests pass !
  When I tested on a windows VM with a single processor , tests pass, which could describe here a multithreading issue over static editor ?
  I've tried synchronized blocks (<code>synchronised(mEditor)</code>) , initializing JavaFX environement by refering to this thread : <a href="https://stackoverflow.com/questions/11385604/how-do-you-unit-test-a-javafx-controller-with-junit">How do you unit test a JavaFX controller with JUnit</a>, but I always end up with this random behaviour, in which some tests pass, some tests fail and if run again tests could pass or fail randomly.</p>