Bug 65176

Summary: Introduce forkmode in JUnitLauncher task
Product: Ant Reporter: Allan Francani <allan.francani>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: 1.10.8   
Target Milestone: 1.10.14   
Hardware: PC   
OS: Mac OS X 10.1   

Description Allan Francani 2021-03-09 11:11:42 UTC
I recently tried to upgrade from JUnit 4 to 5 in a Java project that uses Ant to run tests for CI.

The project has many legacy classes with static attributes, so the tests rely on the forkmode="perTest" attribute of the JUnit task to isolate the context for each test class.

The migrating to JUnit 5 involves the use of the new JUnitLauncher task, which has no forkmode and therefore prevents us from migrating.

Is there a plan to implement the forkmode attribute for the JUnitLauncher task?
Comment 1 Jaikiran Pai 2021-08-13 07:15:42 UTC
Hello Allan,

Could you tell us what the junitlauncher task usage looks like in your project? Are you using "testclasses" element within the junitlauncher and then a "fork" nested element in it? More specifically, are you requesting that each of the test classes identified within that "testclasses" element be launched in a forked vm of their own?
Comment 2 Jaikiran Pai 2021-08-13 07:17:14 UTC
Also, sorry about the late reply. I remember noticing this issue when it was initially filed but then forgot to reply and it's already 5 months now!
Comment 3 Allan Francani 2021-08-13 07:34:35 UTC
(In reply to Jaikiran Pai from comment #1)
> Hello Allan,
> 
> Could you tell us what the junitlauncher task usage looks like in your
> project? Are you using "testclasses" element within the junitlauncher and
> then a "fork" nested element in it? More specifically, are you requesting
> that each of the test classes identified within that "testclasses" element
> be launched in a forked vm of their own?

Hello,

Yes, I would use the testclasses element to define the list of test classes to run and a fork element to define the forking strategy. What I am looking for is a mechanism that would be similar to the junit task forkmode="perTest" attribute: forking the JVM for each test class that is selected by the testclasses element.
Comment 4 Tomasz Kowalczewski 2023-01-04 13:40:19 UTC
We have encountered similar issue. Is there any interest in implementing this?
Comment 5 Jaikiran Pai 2023-08-12 15:15:20 UTC
This has now been implemented. A new optional attribute "forkMode" can be provided to the <fork> element of <junitlauncher> task. That attribute allows "perTestClass" as a value and if that is what is specified then each of the test  class is forked in a separate JVM of its own. 

Here's the documentation https://github.com/apache/ant/blob/master/manual/Tasks/junitlauncher.html#L643:

        <td>forkMode</td>
        <td>Controls how many JVMs are launched for the forked tests. Allowed values are:
            <ul class="inlinelist">
                <li><code>perTestClass</code> - This mode launches each test class in a
                    separately forked JVM</li>
            </ul>
            <p><em>Since Ant 1.10.14</em></p>
        </td>
        <td>No; defaults to launching all test classes in one single forked JVM.</td>

This will be available in the upcoming 1.10.14 release.

It will be helpful if one of you could try it out against our nightly Ant  builds https://ci-builds.apache.org/job/Ant/job/Ant_Nightly/lastSuccessfulBuild/artifact/distribution/