So, we have
JavaFX 1.2 and
upgraded support for NetBeans IDE 6.5.1. After a few hours of use, I can confirm that the programmer's experience is now really improved, with the editor much more supportive than before. What's missing of importance still? Simple answer: JUnit support.

In fact, strangely enough, there's no support for tests; not even a specific folder to put them in. A few people blogged about some tricks to run JUnit in a JavaFX project, treating JUnit as a simple library; but this approach didn't satisfy me, also because I want something that produces the regular reports (e.g., to be used by Hudson) and doesn't require to write too much extra code (such as explicitly creating TestSuites); in a word, something that will allow me to have all the things working just as they are when JUnit tests will be available in NetBeans IDE.

I was able to do that, at the price of applying two small patches to JUnit. Here it is how to do in six steps.

1. Create a new JavaFX project and put a dependency on your primary project

You need to do that because you don't want to put test sources together with regular sources. You have to create a Dummy.fx class with a void run() function and declare it as the main class in the project properties: NetBeans treats every project as it was a complete application and wants an entry point.

public function run(): Void { }

You need to put the JAR of JUnit as a library of your test project - but a patched version of JUnit (see below).

2. Create the tests

Keep the usual conventions, such as putting a test in the same package as the fixture; name the test with the ****Test pattern and test methods test***(). Since in JavaFX there are no annotations, you have to use the JUnit 3.x approach, that is you have to extend TestCase. I'm including a sample of a real test from blueBill Mobile (which just a few not relevant stuff omitted for brevity). Note that to assert the equality of two sequences I had to write a small ad hoc function, as sequences aren't array and aren't known to JUnit. Such code (and other similar) should probably packed in a specific, small library.

4. Add a few properties in nbproject/project.properties

5. Patch JUnit

Now the most annoying part. Everything would already work, but for a detail: JUnit will complain about test classes having more than one constructor. Unfortunately, while JavaFX has got no constructors in the language, it creates synthetic code with two constructors in the bytecode (one with no parameters and one with a boolean parameter). I don't know what's it for, but for sure it makes JUnit complain. We have to patch JUnit. I downloaded JUnit 4.6 (I bet it's ok also 4.5) and patched these two files:

I believe that JUnit is rather extensible and one can specify his own runner. Perhaps one could write some code and embed it together with tests, rather than patching the original, but unfortunately configuring this stuff requires annotations, and in JavaFX no annotations...

6. Create a small wrapper Ant script (for Hudson only)

Ok, at this time we have two NetBeans projects, the regular one and the one with tests. If you want to run this stuff under Hudson, put both of them into a directory and create this small script:

Basically, the first call to ant might be redundant, as building the test project will make the first project to compile.

Ok, this can be surely improved, but in the meantime it just works, and you can start writing tests as they should be. The only important limitation it's that it won't work for a project configured with the Mobile profile, because of what sounds as a JavaFX compiler bug. My project is for the mobile profile, but I make sure that Hudson configures it as a desktop profile. I hope to fix this soon. Maybe in the meantime we will have NetBeans 6.7 final with JavaFX + JUnit support? Who knows.

What are you saying? Oh, you'd like to see an example project to try. Ok, blueBill Mobile isn't ready for primetime, but if you just want to look at how I configured tests you can check it out from Kenai: