-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbuild-junit.xml
120 lines (106 loc) · 5.38 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
<?xml version="1.0" encoding="UTF-8" ?>
<!--
This file is part of SoSy-Lab Java-Project Template,
a collection of common files and build definitions for Java projects:
https://gitlab.com/sosy-lab/software/java-project-template
SPDX-FileCopyrightText: 2018-2020 Dirk Beyer <https://www.sosy-lab.org>
SPDX-License-Identifier: Apache-2.0
-->
<!-- vim: set tabstop=8 shiftwidth=4 expandtab filetype=ant : -->
<project name="junit" basedir="."
xmlns:jacoco="antlib:org.jacoco.ant">
<!-- Targets for running JUnit. -->
<!-- DO NOT EDIT LOCALLY!
Keep this file synchronized with
https://gitlab.com/sosy-lab/software/java-project-template
-->
<!-- Can be overridden from including file. -->
<property name="junit.dir" value="junit"/>
<!-- Define property that contains the Ant version for getting the matching ant-junit version. -->
<antversion property="ant.version.exact"/>
<!-- Load the JUnit plugin for Ant if it's not installed. -->
<condition property="ant.junit.available">
<typefound name="junit"/>
</condition>
<target name="load-junit" depends="resolve-dependencies" unless="ant.junit.available">
<taskdef name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
classpath="${ivy.jar.dir}/ant-junit.jar:${ivy.jar.dir}/ant-junit4.jar"/>
<taskdef name="junitreport"
classname="org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator"
classpath="${ivy.jar.dir}/ant-junit.jar:${ivy.jar.dir}/ant-junit4.jar"/>
</target>
<target name="init-unit-tests">
<!-- Provide default classpath if none is specified. -->
<path id="classpath.junit">
<path refid="classpath"/>
</path>
<mkdir dir="${junit.dir}"/>
</target>
<target name="unit-tests" depends="build, load-junit, init-unit-tests" description="Run all JUnit tests">
<delete dir="{junit.dir}"/>
<junit fork="true" printSummary="true" showOutput="false" failureproperty="junit.failed" timeout="600000">
<assertions><enable/></assertions>
<formatter type="xml"/>
<classpath refid="classpath.junit"/>
<sysproperty key="java.awt.headless" value="true" />
<batchtest fork="true" todir="${junit.dir}">
<fileset dir="${class.dir}">
<include name="**/*Test.*"/>
<exclude name="**/*$*Test.*"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.dir}">
<fileset dir="${junit.dir}" includes="TEST-*.xml"/>
<report format="noframes"/>
</junitreport>
<move file="junit-noframes.html" tofile="JUnit.html"/>
<fail if="junit.failed" message="JUnit tests failed, look at JUnit.html"/>
</target>
<target name="load-jacoco" depends="resolve-dependencies">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath><fileset dir="${ivy.jar.dir}" includes="org.jacoco.*.jar asm*.jar"/></classpath>
</taskdef>
</target>
<target name="unit-tests-coverage" depends="build, load-junit, load-jacoco, init-unit-tests" description="Run all JUnit tests with coverage report">
<delete dir="{junit.dir}"/>
<jacoco:coverage destfile="${junit.dir}/jacoco.exec" excludes="**/*Test*:**/Dummy*">
<junit fork="true" printSummary="true" showOutput="false" failureproperty="junit.failed" timeout="600000">
<assertions><enable/></assertions>
<formatter type="xml"/>
<classpath refid="classpath.junit"/>
<sysproperty key="java.awt.headless" value="true" />
<batchtest fork="true" todir="${junit.dir}">
<fileset dir="${class.dir}">
<include name="**/*Test.*"/>
<exclude name="**/*$*Test.*"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<jacoco:report>
<executiondata><file file="${junit.dir}/jacoco.exec"/></executiondata>
<structure name="${ant.project.name}">
<classfiles><fileset dir="${class.dir}" excludes="**/*Test*,**/Dummy*/"/></classfiles>
<sourcefiles encoding="UTF-8"><fileset dir="${source.dir}" excludes="**/*Test*,**/Dummy*/"/></sourcefiles>
</structure>
<html destdir="JUnit-coverage"/>
<xml destfile="${junit.dir}/coverage.xml"/>
<csv destfile="${junit.dir}/coverage.csv"/>
</jacoco:report>
<junitreport todir="${junit.dir}">
<fileset dir="${junit.dir}" includes="TEST-*.xml"/>
<report format="noframes"/>
</junitreport>
<exec executable="awk" failifexecutionfails="false" failonerror="false">
<arg value="-F,"/>
<arg value='-v'/>
<arg value='OFS='/>
<arg value='{ instructions += $4 + $5; covered += $5 } END { print covered, " / ", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }'/>
<arg value="${junit.dir}/coverage.csv"/>
</exec>
<move file="junit-noframes.html" tofile="JUnit.html"/>
<fail if="junit.failed" message="JUnit tests failed, look at JUnit.html"/>
</target>
</project>