I looked in the sources, and it looks like testSrcDirs on the Test task is not even used (other than by TestNG). What is the appropriate way to do this?
As you already noticed, ‘testSrcDirs’ is just for TestNG. What’s necessary in any case is to pass the compiled test code via ‘classesDir’ (this is how Gradle finds the tests to be executed), and the compiled test code plus its dependencies via ‘classpath’ (this is the class path for test execution). One way to achieve this is to add the directories to the ‘test’ source set and then work with includes/excludes on the test tasks. Another way is to set up a separate source set, which will automatically give you a separate compile/processResources/classes task, and separate compile/runtime configurations.
Basically the difference between the two is that one sets the -Djavafx.toolkit flag, and one doesn’t. The tests that require the flag have been physically separated from the other tests. It is less than ideal because there’s a bunch of logic here. Also both have forkEvery = 1, so in theory if I could hook in and change the VM settings for each forked VM based on the test that was about to run, I’d be golden. I tried that (by changing the VM args or system properties – tried both approaches – in the beforeSuite handler, but this looks like it happens after the VM is forked, so I was hosed).
I’m still playing around with this to try to get the right magic formula that will work. For example, in testWithStub it has a closure to omit certain classes. However this is probably only needed because both of these two test tasks are by default using the “test” source set. I wanted to be able to tell the testWithStub to use the “stub” source set, but I don’t see any direct way to do that.
I’m mostly just flailing around at the moment trying everything to see if I can get a better understanding of the mental model here and so far failing miserably :-). I’ll report back in once I’ve figured it out.