This discussion is archived
11 Replies Latest reply: Dec 7, 2012 9:36 AM by PDVieira RSS

JavaFX, Junit, Netbeans problem

PDVieira Newbie
Currently Being Moderated
Hi,

After setting up everything for running tests using JUnit I stumbled upon an issue.

The app that I was going to test runs fine but the tests (JUnit part) don't. I get this error: "java.lang.NoClassDefFoundError: javafx/scene/Group"

Does anyone know what's wrong?

Thanks in advance,
  • 1. Re: JavaFX, Junit, Netbeans problem
    MiPa Pro
    Currently Being Moderated
    Have you made sure your JUnit setup contains the JavaFX runtime jar?
  • 2. Re: JavaFX, Junit, Netbeans problem
    PDVieira Newbie
    Currently Being Moderated
    Where do you configure that?
  • 3. Re: JavaFX, Junit, Netbeans problem
    jsmith Guru
    Currently Being Moderated
    Find jfxrt.jar (it will probably be in your jre/lib directory) and place it on the classpath when you run your junit test.
    javac -classpath "C:\Program Files (x86)\Java\jdk1.7.0_09\jre\lib\jfxrt.jar" <test case java file>
    java -classpath "C:\Program Files (x86)\Java\jdk1.7.0_09\jre\lib\jfxrt.jar;." junit.textui.TestRunner <test case class>
    When jfxrt.jar is finally placed on the default Java boot classpath (maybe jdk8), then the extra classpath configuration of it will (finally) no longer be necessary.
  • 4. Re: JavaFX, Junit, Netbeans problem
    PDVieira Newbie
    Currently Being Moderated
    Isn't there a way to configure that on netbeans? without having to run that through the command line?

    Thanks, best regards,
  • 5. Re: JavaFX, Junit, Netbeans problem
    jsmith Guru
    Currently Being Moderated
    I'm curious how you will use junit to test a JavaFX app.
    How will the junit test work and what will it do?
    Will it launch the JavaFX app?
    Will it trigger events on the app?
    What will it evaluate when comparing expecteds to actuals?

    I don't use NetBeans that much, but I downloaded 7.3 beta 2 + a jdk8 pre-release build and installed them both. I created a new JavaFX project in NetBeans, then right-clicked on the generated HelloWorld class and selected Tools | Create Tests. NetBeans went and downloaded junit and a junit plugin for NetBeans, then it generated a Test harness for the public methods. It set each generated test harness method to deliberately fail because they were just dummy methods. I changed the fail statements in the test harnesses to assertTrue(true), then I right clicked again on the original HelloWorld class and selected Test. The junit tests ran. The one which executed the main method passed. The one which executed the start method failed because the app wasn't on the JavaFX application thread. There weren't any compilation errors or missing classes - so I guess that something was clever enough to get jfxrt.jar on the classpath without me needing to do anything.
  • 6. Re: JavaFX, Junit, Netbeans problem
    PDVieira Newbie
    Currently Being Moderated
    Hi again jsmith,
    thank you for taking the time to answer my question.

    What I really want to test with junit is the "logic" of the application, anything that is related to the presentation layer that interacts directly with the output devices won't be tested. I don't intend to launch the javafx app.
    But of course, for this to be possible one has to previously separate the logic from the presentation on the app code itself.

    I tend not to use Netbeans myself as well but since that is the platform of choice of the client I have to go with it. I really needed to fix this issue through a GA release of Netbeans, there must be some way of doing it since junit is tightly integrated with Netbeans.


    Thanks, :)
  • 7. Re: JavaFX, Junit, Netbeans problem
    jsmith Guru
    Currently Being Moderated
    Did you try the steps from my second post?

    It just worked for me. There was no special setup required.
  • 8. Re: JavaFX, Junit, Netbeans problem
    PDVieira Newbie
    Currently Being Moderated
    But you're using a beta version of netbeans and java 8. I would like to use java 7 and netbeans.

    Thanks,
  • 9. Re: JavaFX, Junit, Netbeans problem
    jsmith Guru
    Currently Being Moderated
    But you're using a beta version of netbeans and java 8. I would like to use java 7 and netbeans.
    Although I was using a beta netbeans and java8, the features I used are also present in java 7 and NetBeans 7.2 and the instructions apply equally. I installed jdk7u9 and NetBeans 7.2.1 and everything worked just the same as it did when I used NetBeans 7.3beta + jdk8b65.
  • 10. Re: JavaFX, Junit, Netbeans problem
    Hank P. Newbie
    Currently Being Moderated
    Hello,

    Did you try to add the jfx - runtime to the test libraries?

    Second thing you can do is going to Project Properties and add "-Djava.library.path=./jrepath" in the VM Options.
  • 11. Re: JavaFX, Junit, Netbeans problem
    PDVieira Newbie
    Currently Being Moderated
    @jsmith
    It didn't work for me using netbeans 7.2.1 and java 7. Before creating this thread I did everything you listed, that's why I decided to recur to the OTN foruns.

    Even though, thanks for your time.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points