TestFX / Monocle

Pre-packaged builds of Monocle (OpenJFX)
GNU General Public License v2.0
50 stars 24 forks source link

Monocle on build servers (JDK 8) #62

Closed habahut closed 9 months ago

habahut commented 6 years ago

Hello, I'm looking to build a javaFX app with headless unit testing with Monocle. I've been able to get headless testing to work locally with building the monocle jar myself and loading it into my /Extensions java folder as specified here: https://stackoverflow.com/questions/29116819/javafx-maven-testfx-monocle-dont-work-together. But I don't own the build servers so it will be difficult for me to install Monocle into the Java extensions folder.

I am using Maven and tried using the tag https://maven.apache.org/pom.html#Extensions to include monocle:

<extensions>
        <extension>
            <groupId>org.testfx</groupId>
            <artifactId>openjfx-monocle</artifactId>
            <version>8u76-b04</version>
        </extension>
</extensions>  

This doesn't work, even with a separate dependency in the tag. I also tried including the monocle jar in the source code and including it with the java.ext.dirs parameter:

<argLine>-Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw -Dheadless.geometry=1600x1200-32 -Djava.ext.dirs=:<path>/monocle-jars</argLine>

But this gives me this error:

java.lang.NoClassDefFoundError: javafx/application/Application

I think that changing to a custom java.ext.dirs value causes the javafx code to not be found. Is there any guidance on how to use this tool when one doesn't own the build servers and can't modify the java install on them?

brcolow commented 6 years ago

Usually you add monocle as a standard Maven dependency, not as an extension. For example by adding the dependency to your pom.xml of your project like so:

<dependencies>
  <!-- ... -->
  <dependency>
    <groupId>org.testfx</groupId>
    <artifactId>openjfx-monocle</artifactId>
    <version>jdk-9+181</version>
    <scope>test</scope>
  </dependency>
</dependencies>

This will make it so that the classpath is populated with the Monocle classes when you are testing your application (most likely by using maven-surefire-plugin and/or maven-failsafe-plugin). Then the system properties that you listed should properly take affect and make your TestFX tests run in headless mode. Let me know if I am missing something about your question.