Is it possible to "forkEvery" by method, rather than by class?

(Jon Austen) #1

Is it possible to “forkEvery” by method, rather than by class?

I want to use a JUnit test suite, which is basically a single class that calls multiple methods.

I believe that the problem I am having is that Gradle recognizes the entire test suite as a single class ( typically called “AllTests.class” ) and doesn’t fork upon all the methods that are found within the embedded class references within the entire suite.

Is it possible to “forkEvery=method” or something like that?

Until I figure it out, it seems that my Gradle “Junit Suite” runs on only one thread.

In my project (see links below) i have a runAllTests task that runs the JUnit suite on one thread . I also have a runSkipSuite task that skips the suite class and filters by test classes in the gradle task which is a method that works and forks properly but I would have preferred the suite method.

NOTE: my problematic project is at:

and my Hub/Node server scripts are at :

(Jon Austen) #2

So, my theory at the moment is that the issue of forking-by-method has something to do with the @Before and @After annotations in the TestSuite class?

After investigation, I find that the Before and After do not even get called and so I cannot verify my theory. See my test case here:

Can anyone explain why this simple JUnit project isn’t forking?

It will only run sequentially when I use the TestSuite runner method.

I can get it to fork if I create a task filter to run only the test classes (without the suite) but that is not my question here.

(Jon Austen) #3

I finally got it ONLY partially working here:

I still can’t quite get it working using a standard JUnit test suite class BUT I am able to get it working by using the Gradle forking method with a class filter. (See the link above)

I also created another, simpler, project to try to reproduce the issue and am having a similar problem. See this project here:

So, I am still hoping someone can answer my question.

Because of this problem I am unable to run static shared instances of HTTP server or JSON-RemoteWebDriver servers because if I do initialize those in a AllTests suite class then the tests run sequentially rather than forked.

Perhaps I could run a static server from the Gradle task, but is that what is recommended?