Skip to content

Commit 0c580f6

Browse files
committed
build: Standardize test output and decouple JaCoCo coverage
Refactors the Ant build scripts across client, command, donkey, and server projects to improve CI integration and local developer experience. Changes: * Decoupled Coverage: Separated unit test execution (`test-run`) from code coverage instrumentation (`test-coverage`). Developers can now run tests locally without the performance penalty of the JaCoCo agent unless explicitly requested. * Standardized Output: Consolidated all test artifacts into a unified, Gradle-compliant directory structure: - Raw results: `build/test-results/test` - HTML/XML Reports: `build/reports/tests` and `build/reports/jacoco` Single project Usage: - Run standard unit tests: `ant test-run` - Run tests with coverage: `ant test-coverage` Full Build Usage: - Run standard unit tests: `ant -f mirth-build.xml build` - Run tests with coverage: `ant -f mirth-build.xml build -Dcoverage=true` Signed-off-by: Tony Germano <tony@germano.name>
1 parent 41858d4 commit 0c580f6

9 files changed

Lines changed: 404 additions & 144 deletions

File tree

client/ant-build.xml

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project name="mirth-client" basedir="." default="help" xmlns:unless="ant:unless">
1+
<project name="mirth-client" basedir="." default="help"
2+
xmlns:jacoco="antlib:org.jacoco.ant" xmlns:unless="ant:unless" xmlns:if="ant:if">
3+
24
<target name="help">
35
<echo>OIE Client Build Help</echo>
46
<echo>-----------------------</echo>
@@ -352,32 +354,78 @@
352354
resource="org/jacoco/ant/antlib.xml"
353355
classpathref="jacoco.classpath"/>
354356

357+
<target name="test-coverage" depends="test-compile">
358+
<description>Run unit tests WITH JaCoCo coverage.</description>
359+
360+
<delete dir="${jacoco.data.dir}" />
361+
<delete dir="${reports.jacoco.dir}" />
362+
363+
<jacoco:agent property="jacoco.agent.arg"
364+
destfile="${jacoco.exec.file}"
365+
exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" />
366+
367+
<antcall target="test-run" />
368+
369+
<jacoco:report>
370+
<executiondata>
371+
<file file="${jacoco.exec.file}" />
372+
</executiondata>
373+
<structure name="${ant.project.name}">
374+
<classfiles>
375+
<fileset dir="${classes}" />
376+
</classfiles>
377+
<sourcefiles encoding="UTF-8">
378+
<fileset dir="${src}" />
379+
</sourcefiles>
380+
</structure>
381+
<html destdir="${reports.jacoco.html}" />
382+
<xml destfile="${reports.jacoco.xml}"/>
383+
</jacoco:report>
384+
</target>
385+
355386
<target name="test-run" depends="test-compile">
356-
<property name="junit-reports" value="junit-reports" />
357-
<property name="code-coverage-reports" value="code-coverage-reports" />
358-
<mkdir dir="${junit-reports}" />
359-
<mkdir dir="${code-coverage-reports}" />
360-
361-
<jacoco:coverage destfile="${code-coverage-reports}/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant" exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" >
362-
<junit haltonfailure="false" failureproperty="test.failed" errorproperty="test.failed" fork="true" forkmode="once">
363-
<jvmarg value="-Xms128m" />
364-
<jvmarg value="-Xmx2048m" />
365-
<!-- https://stackoverflow.com/questions/54205486 -->
366-
<jvmarg value="-Xshare:off" />
367-
<classpath>
368-
<path refid="testclasspath" />
369-
<dirset dir="${test_classes}"/>
370-
</classpath>
371-
<formatter type="xml" />
372-
<batchtest todir="${junit-reports}">
373-
<fileset dir="${test_classes}">
374-
<include name="**/*Test.class" />
375-
</fileset>
376-
</batchtest>
377-
</junit>
378-
</jacoco:coverage>
379-
380-
<fail if="test.failed" message="Unit tests failed. Check reports for details."/>
387+
<description>Run unit tests. Coverage is only enabled if 'jacoco.agent.arg' is set.</description>
388+
389+
<delete dir="${test.results.dir}" />
390+
<delete dir="${reports.tests.dir}" />
391+
<mkdir dir="${test.results.dir}" />
392+
<mkdir dir="${reports.tests.dir}" />
393+
394+
<junit haltonfailure="false"
395+
failureproperty="test.failed"
396+
errorproperty="test.failed"
397+
fork="true"
398+
forkmode="once">
399+
400+
<jvmarg value="-Xms128m" />
401+
<jvmarg value="-Xmx2048m" />
402+
<!-- https://stackoverflow.com/questions/54205486 -->
403+
<jvmarg value="-Xshare:off" />
404+
<jvmarg line="${jacoco.agent.arg}" if:set="jacoco.agent.arg" />
405+
406+
<classpath>
407+
<path refid="testclasspath" />
408+
<dirset dir="${test_classes}"/>
409+
</classpath>
410+
411+
<formatter type="xml" />
412+
413+
<batchtest todir="${test.results.dir}">
414+
<fileset dir="${test_classes}">
415+
<include name="**/*Test.class" />
416+
</fileset>
417+
</batchtest>
418+
</junit>
419+
420+
<!-- Generate HTML report from JUnit XML output -->
421+
<junitreport todir="${test.results.dir}">
422+
<fileset dir="${test.results.dir}">
423+
<include name="TEST-*.xml"/>
424+
</fileset>
425+
<report format="frames" todir="${reports.tests.dir}" />
426+
</junitreport>
427+
428+
<fail if="test.failed" message="Unit tests failed. For details, check reports in ${reports.tests.dir}."/>
381429
</target>
382430

383431
<target name="remove-classes" depends="init">

client/build.properties

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# top level directories
22
src=${basedir}/src
33
test=${basedir}/test
4+
build.dir=${basedir}/build
45
server=${basedir}/../server
56
donkey_src=${basedir}/../donkey/src/main/java
67
donkey_lib=${basedir}/../donkey/lib
@@ -13,5 +14,23 @@ dist=${basedir}/dist
1314
# jars
1415
client.jar=mirth-client.jar
1516

17+
# Reports
18+
reports.dir=${build.dir}/reports
19+
20+
# JUnit Raw Results (XML)
21+
test.results.dir=${build.dir}/test-results/test
22+
23+
# JUnit Human-Readable Reports (HTML)
24+
reports.tests.dir=${reports.dir}/tests/test
25+
26+
# JaCoCo Execution Data (.exec)
27+
jacoco.data.dir=${build.dir}/jacoco
28+
jacoco.exec.file=${jacoco.data.dir}/test.exec
29+
30+
# JaCoCo Reports (HTML and XML)
31+
reports.jacoco.dir=${reports.dir}/jacoco/test
32+
reports.jacoco.html=${reports.jacoco.dir}/html
33+
reports.jacoco.xml=${reports.jacoco.dir}/jacocoTestReport.xml
34+
1635
# This value is used as the modified time for the files inside of jar, zip, and war files
1736
archive.entry.date=1999-01-01T00:00:00.000Z

command/build.properties

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ src=${basedir}/src
33
classes=${basedir}/classes
44
lib=${basedir}/lib
55
conf=${basedir}/conf
6-
build=${basedir}/build
6+
build.dir=${basedir}/build
77
dist=${basedir}/dist
88
test=${basedir}/test
99
testlib=${basedir}/testlib
@@ -14,5 +14,23 @@ server=${basedir}/../server
1414
cli.jar=mirth-cli.jar
1515
cli-launcher.jar=mirth-cli-launcher.jar
1616

17+
# Reports
18+
reports.dir=${build.dir}/reports
19+
20+
# JUnit Raw Results (XML)
21+
test.results.dir=${build.dir}/test-results/test
22+
23+
# JUnit Human-Readable Reports (HTML)
24+
reports.tests.dir=${reports.dir}/tests/test
25+
26+
# JaCoCo Execution Data (.exec)
27+
jacoco.data.dir=${build.dir}/jacoco
28+
jacoco.exec.file=${jacoco.data.dir}/test.exec
29+
30+
# JaCoCo Reports (HTML and XML)
31+
reports.jacoco.dir=${reports.dir}/jacoco/test
32+
reports.jacoco.html=${reports.jacoco.dir}/html
33+
reports.jacoco.xml=${reports.jacoco.dir}/jacocoTestReport.xml
34+
1735
# This value is used as the modified time for the files inside of jar, zip, and war files
1836
archive.entry.date=1999-01-01T00:00:00.000Z

command/build.xml

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project name="mirth-cli" basedir="." default="build" xmlns:unless="ant:unless">
1+
<project name="mirth-cli" basedir="." default="build"
2+
xmlns:jacoco="antlib:org.jacoco.ant" xmlns:unless="ant:unless" xmlns:if="ant:if">
3+
24
<target name="init">
35
<property file="build.properties" />
46

@@ -12,7 +14,7 @@
1214

1315
<target name="clean" depends="init">
1416
<delete dir="${classes}" />
15-
<delete dir="${build}" />
17+
<delete dir="${build.dir}" />
1618
<delete dir="${dist}" />
1719
<delete dir="${test_classes}" />
1820
</target>
@@ -25,28 +27,28 @@
2527
</target>
2628

2729
<target name="build" depends="compile">
28-
<mkdir dir="${build}" />
30+
<mkdir dir="${build.dir}" />
2931

3032
<!-- log4j2.properties file -->
31-
<mkdir dir="${build}/conf" />
33+
<mkdir dir="${build.dir}/conf" />
3234

33-
<copy todir="${build}/conf">
35+
<copy todir="${build.dir}/conf">
3436
<fileset dir="${conf}" />
3537
</copy>
3638

3739
<!-- cli-lib -->
38-
<mkdir dir="${build}/cli-lib" />
40+
<mkdir dir="${build.dir}/cli-lib" />
3941

40-
<copy todir="${build}/cli-lib">
42+
<copy todir="${build.dir}/cli-lib">
4143
<fileset dir="${lib}" />
4244
</copy>
4345

44-
<jar destfile="${build}/${cli.jar}" basedir="${classes}" modificationTime="${archive.entry.date}">
46+
<jar destfile="${build.dir}/${cli.jar}" basedir="${classes}" modificationTime="${archive.entry.date}">
4547
<include name="com/mirth/connect/cli/**" />
4648
<exclude name="com/mirth/connect/cli/launcher/**" />
4749
</jar>
4850

49-
<jar destfile="${build}/${cli-launcher.jar}" basedir="${classes}" modificationTime="${archive.entry.date}">
51+
<jar destfile="${build.dir}/${cli-launcher.jar}" basedir="${classes}" modificationTime="${archive.entry.date}">
5052
<include name="com/mirth/connect/cli/launcher/**" />
5153

5254
<manifest>
@@ -91,31 +93,77 @@
9193
resource="org/jacoco/ant/antlib.xml"
9294
classpathref="jacoco.classpath"/>
9395

96+
<target name="test-coverage" depends="test-compile">
97+
<description>Run unit tests WITH JaCoCo coverage.</description>
98+
99+
<delete dir="${jacoco.data.dir}" />
100+
<delete dir="${reports.jacoco.dir}" />
101+
102+
<jacoco:agent property="jacoco.agent.arg"
103+
destfile="${jacoco.exec.file}"
104+
exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" />
105+
106+
<antcall target="test-run" />
107+
108+
<jacoco:report>
109+
<executiondata>
110+
<file file="${jacoco.exec.file}" />
111+
</executiondata>
112+
<structure name="${ant.project.name}">
113+
<classfiles>
114+
<fileset dir="${classes}" />
115+
</classfiles>
116+
<sourcefiles encoding="UTF-8">
117+
<fileset dir="${src}" />
118+
</sourcefiles>
119+
</structure>
120+
<html destdir="${reports.jacoco.html}" />
121+
<xml destfile="${reports.jacoco.xml}"/>
122+
</jacoco:report>
123+
</target>
124+
94125
<target name="test-run" depends="test-compile">
95-
<property name="junit-reports" value="junit-reports" />
96-
<property name="code-coverage-reports" value="code-coverage-reports" />
97-
<mkdir dir="${junit-reports}" />
98-
<mkdir dir="${code-coverage-reports}" />
99-
100-
<jacoco:coverage destfile="${code-coverage-reports}/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant" exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" >
101-
<junit haltonfailure="false" failureproperty="test.failed" errorproperty="test.failed" fork="true" forkmode="once">
102-
<jvmarg value="-Xms128m" />
103-
<jvmarg value="-Xmx2048m" />
104-
<!-- https://stackoverflow.com/questions/54205486 -->
105-
<jvmarg value="-Xshare:off" />
106-
<classpath>
107-
<path refid="testclasspath" />
108-
<dirset dir="${test_classes}"/>
109-
</classpath>
110-
<formatter type="xml" />
111-
<batchtest todir="${junit-reports}">
112-
<fileset dir="${test_classes}">
113-
<include name="**/*Test.class" />
114-
</fileset>
115-
</batchtest>
116-
</junit>
117-
</jacoco:coverage>
118-
119-
<fail if="test.failed" message="Unit tests failed. Check reports for details."/>
126+
<description>Run unit tests. Coverage is only enabled if 'jacoco.agent.arg' is set.</description>
127+
128+
<delete dir="${test.results.dir}" />
129+
<delete dir="${reports.tests.dir}" />
130+
<mkdir dir="${test.results.dir}" />
131+
<mkdir dir="${reports.tests.dir}" />
132+
133+
<junit haltonfailure="false"
134+
failureproperty="test.failed"
135+
errorproperty="test.failed"
136+
fork="true"
137+
forkmode="once">
138+
139+
<jvmarg value="-Xms128m" />
140+
<jvmarg value="-Xmx2048m" />
141+
<!-- https://stackoverflow.com/questions/54205486 -->
142+
<jvmarg value="-Xshare:off" />
143+
<jvmarg line="${jacoco.agent.arg}" if:set="jacoco.agent.arg" />
144+
145+
<classpath>
146+
<path refid="testclasspath" />
147+
<dirset dir="${test_classes}"/>
148+
</classpath>
149+
150+
<formatter type="xml" />
151+
152+
<batchtest todir="${test.results.dir}">
153+
<fileset dir="${test_classes}">
154+
<include name="**/*Test.class" />
155+
</fileset>
156+
</batchtest>
157+
</junit>
158+
159+
<!-- Generate HTML report from JUnit XML output -->
160+
<junitreport todir="${test.results.dir}">
161+
<fileset dir="${test.results.dir}">
162+
<include name="TEST-*.xml"/>
163+
</fileset>
164+
<report format="frames" todir="${reports.tests.dir}" />
165+
</junitreport>
166+
167+
<fail if="test.failed" message="Unit tests failed. For details, check reports in ${reports.tests.dir}."/>
120168
</target>
121169
</project>

donkey/build.properties

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ src=${basedir}/src/main/java
33
classes=${basedir}/classes
44
test=${basedir}/src/test/java
55
test_classes=${basedir}/test_classes
6+
build.dir=${basedir}/build
67
lib=${basedir}/lib
78
testlib=${basedir}/testlib
89
setup=${basedir}/setup
@@ -19,5 +20,23 @@ setup=${basedir}/setup
1920
setup.lib=${setup}/lib
2021
setup.docs=${setup}/docs
2122

23+
# Reports
24+
reports.dir=${build.dir}/reports
25+
26+
# JUnit Raw Results (XML)
27+
test.results.dir=${build.dir}/test-results/test
28+
29+
# JUnit Human-Readable Reports (HTML)
30+
reports.tests.dir=${reports.dir}/tests/test
31+
32+
# JaCoCo Execution Data (.exec)
33+
jacoco.data.dir=${build.dir}/jacoco
34+
jacoco.exec.file=${jacoco.data.dir}/test.exec
35+
36+
# JaCoCo Reports (HTML and XML)
37+
reports.jacoco.dir=${reports.dir}/jacoco/test
38+
reports.jacoco.html=${reports.jacoco.dir}/html
39+
reports.jacoco.xml=${reports.jacoco.dir}/jacocoTestReport.xml
40+
2241
# This value is used as the modified time for the files inside of jar, zip, and war files
2342
archive.entry.date=1999-01-01T00:00:00.000Z

0 commit comments

Comments
 (0)