Skip to content

Commit

Permalink
JUnit 5 tests and coverage are now supported
Browse files Browse the repository at this point in the history
The workaround is to do without the <junitlauncher> and <coverage> tasks
provided by Ant and JaCoCo (which do not work together), and to run
JUnit with a plain <java> task and pass the JaCoCo agent to the JVM.
  • Loading branch information
sylvainhalle committed Aug 26, 2021
1 parent 5947586 commit feac3d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* A simple main class used to test the build file, using test written with
* JUnit version 4.
*/
public class MyClassTest4
public class MyClassV4Test
{

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* JUnit version 5.
*/
@org.junit.Ignore // This to tell JUnit4 to ignore this file
public class MyClassTest5
public class MyClassV5Test
{

@Test
Expand Down
24 changes: 10 additions & 14 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
xmlns:jacoco="antlib:org.jacoco.ant">

<!-- The build script's version number. Do not edit! -->
<property name="antrun.version" value="1.7"/>
<property name="antrun.version" value="1.7.1"/>

<!-- Load project properties from XML file -->
<xmlproperty file="config.xml"/>
Expand Down Expand Up @@ -299,19 +299,15 @@
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${build.libdir}/jacocoant.jar"/>
</taskdef>
<jacoco:coverage destfile="${test.reportdir}/jacoco.exec">
<junit printsummary="yes" haltonfailure="false" fork="true"
failureproperty="test.failed">
<classpath refid="build.test.classpath"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${test.reportdir}">
<fileset dir="${build.test.srcdir}">
<include name="${build.test.filenamepattern}"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<!-- Run jUnit. Since the jacoco task does not support the nested
junitlauncher task (required by jUnit5), we run jUnit manually and
pass the JaCoCo agent as a parameter to the JVM. -->
<jacoco:agent property="agentvmparam" enabled="true" destfile="${test.reportdir}/jacoco.exec" />
<java classpathref="build.test.classpath" classname="org.junit.platform.console.ConsoleLauncher" fork="true" failonerror="true">
<jvmarg value="${agentvmparam}" />
<arg line="--scan-classpath" />
<arg line="--reports-dir ${test.reportdir}" />
</java>
<!-- jUnit report -->
<junitreport todir="${test.reportdir}">
<fileset dir="${test.reportdir}">
Expand Down

0 comments on commit feac3d6

Please sign in to comment.