This content has been marked as final. Show 11 replies
Have you made sure your JUnit setup contains the JavaFX runtime jar?
Where do you configure that?
Find jfxrt.jar (it will probably be in your jre/lib directory) and place it on the classpath when you run your junit test.
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.
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>
Isn't there a way to configure that on netbeans? without having to run that through the command line?
Thanks, best regards,
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.
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.
Did you try the steps from my second post?
It just worked for me. There was no special setup required.
But you're using a beta version of netbeans and java 8. I would like to use java 7 and netbeans.
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.
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.
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.