forked from roborescue/rcrs-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-junit.xml
138 lines (122 loc) · 5.24 KB
/
build-junit.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<project>
<property name="junit.version" value="4.5"/>
<property name="junit.output.dir" value="${build.dir}/junit-results"/>
<property name="cobertura.version" value="1.9.2"/>
<property name="cobertura.output.dir" value="${build.dir}/cobertura-results"/>
<property name="cobertura.output.format" value="html"/>
<property name="cobertura.coveragefile" value="${cobertura.output.dir}/cobertura.ser"/>
<property name="cobertura.instrument.dir" value="${build.dir}/jars-instrumented"/>
<property name="cobertura.home" value="${buildtools.dir}/cobertura-${cobertura.version}"/>
<path id="path.cobertura">
<fileset dir="${cobertura.home}">
<include name="cobertura.jar"/>
<include name="lib/**/*.jar"/>
</fileset>
</path>
<path id="path.cobertura.instrumented">
<fileset dir="${cobertura.instrument.dir}" erroronmissingdir="false">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="path.junit">
<path refid="path.cobertura.instrumented"/>
<path refid="path.cobertura"/>
<path refid="path.common"/>
<fileset dir="${buildtools.dir}">
<include name="junit-${junit.version}.jar"/>
</fileset>
</path>
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<pathelement location="${buildtools.dir}/ant-junit.jar"/>
</classpath>
</taskdef>
<taskdef classpathref="path.cobertura" resource="tasks.properties"/>
<target name="_init-junit">
<mkdir dir="${junit.output.dir}"/>
</target>
<target name="_init-cobertura">
<delete dir="${cobertura.output.dir}" failonerror="false"/>
<delete dir="${cobertura.instrument.dir}" failonerror="false"/>
<mkdir dir="${cobertura.output.dir}"/>
<mkdir dir="${cobertura.instrument.dir}"/>
</target>
<target name="_generate-cobertura-fileset">
<script language="javascript">
<![CDATA[
importClass(org.apache.tools.ant.types.Path);
importClass(org.apache.tools.ant.types.FileSet);
importClass(java.lang.System);
importClass(java.io.File);
var modules = project.getProperty("modules").split(",");
var fileset = new FileSet();
fileset.setDir(new File(project.getProperty("jar.dir")));
for (var i = 0; i < modules.length; ++i) {
fileset.setIncludes(modules[i] + ".jar");
}
project.addReference("cobertura.files", fileset);
]]>
</script>
</target>
<macrodef name="_junit">
<attribute name="module"/>
<sequential>
<echo message="Running JUnit tests for module @{module}"/>
<mkdir dir="${modules.dir}/@{module}/test"/>
<mkdir dir="${build.dir}/@{module}/test"/>
<javac srcdir="${modules.dir}/@{module}/test" destdir="${build.dir}/@{module}/test" classpathref="path.common" debug="${debug}">
<include name="**/*.java"/>
</javac>
<junit fork="true" timeout="120000" printsummary="on">
<sysproperty key="tests.basedir" value="${modules.dir}/@{module}/test"/>
<sysproperty key="net.sourceforge.cobertura.datafile" value="${cobertura.coveragefile}"/>
<sysproperty key="log4j.configuration" value="log4j.test.properties"/>
<classpath>
<path refid="path.junit"/>
<pathelement location="${modules.dir}/@{module}/test"/>
</classpath>
<formatter type="xml"/>
<batchtest todir="${junit.output.dir}">
<fileset dir="${modules.dir}/@{module}/test">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</sequential>
</macrodef>
<target name="junit-run" depends="_init-junit, jars" description="Run the junit tests">
<for list="${modules}" param="module">
<sequential>
<_junit module="@{module}"/>
</sequential>
</for>
</target>
<target name="junit-report" depends="_init-junit" description="Generate the junit report">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="noframes" todir="${junit.output.dir}"/>
</junitreport>
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
<target name="_cobertura-instrument" depends="_init-cobertura, jars, _generate-cobertura-fileset">
<cobertura-instrument todir="${cobertura.instrument.dir}" datafile="${cobertura.coveragefile}">
<fileset refid="cobertura.files"/>
</cobertura-instrument>
</target>
<target name="cobertura-report" depends="_init-cobertura" description="Generate the cobertura test coverage report">
<cobertura-report format="${cobertura.output.format}" datafile="${cobertura.coveragefile}" destdir="${cobertura.output.dir}">
<dirset dir="${basedir}">
<include name="modules/**/src"/>
</dirset>
</cobertura-report>
</target>
<target name="junit" depends="junit-run, junit-report" description="Run the junit tests and generate a report"/>
<target name="cobertura" depends="_cobertura-instrument, junit-run, cobertura-report" description="Run unit tests and generate the cobertura test coverage report"/>
</project>