Adjust build.xml to run JaCoCo coverage when running unit tests when
flag coverage.enabled is set to true, download necessary jars, add jacoco:coverage to junit targets and a testcoveragereport target which produces the coverage report. Also fix a test that is affected by JaCoCo and add slightly more coverage in another test. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1510243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ee39ef2d73
commit
ffc31302a4
138
build.xml
138
build.xml
@ -151,6 +151,12 @@ under the License.
|
||||
<property name="ooxml.jsr173.jar" location="${ooxml.lib}/stax-api-1.0.1.jar"/>
|
||||
<property name="ooxml.jsr173.url" value="${repository.m2}/maven2/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
|
||||
|
||||
<!-- coverage libs -->
|
||||
<property name="jacoco.zip" location="${main.lib}/jacoco-0.6.2.201302030002.zip"/>
|
||||
<property name="jacoco.url" value="${repository.m2}/maven2/org/jacoco/jacoco/0.6.2.201302030002/jacoco-0.6.2.201302030002.zip"/>
|
||||
<property name="asm.jar" location="${main.lib}/asm-all-4.0.jar"/>
|
||||
<property name="asm.url" value="${repository.m2}/maven2/org/ow2/asm/asm-all/4.0/asm-all-4.0.jar"/>
|
||||
|
||||
<!-- See http://www.ecma-international.org/publications/standards/Ecma-376.htm -->
|
||||
<!-- "Copy these file(s), free of charge" -->
|
||||
<property name="ooxml.xsds.ozip" location="${ooxml.lib}/OfficeOpenXML-Part4.zip"/>
|
||||
@ -164,6 +170,11 @@ under the License.
|
||||
<property name="maven.ooxml.xsds.version.id" value="1.0"/>
|
||||
<property name="maven.ooxml.xsds.jar" value="ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
|
||||
|
||||
<!-- Coverage -->
|
||||
<property name="coverage.dir" value="build/coverage"/>
|
||||
<!-- Exclude some uninteresting classes from coverage-instrumentation as we do not want to measure coverage in those packages anyway -->
|
||||
<property name="coverage.excludes" value="org.openxmlformats.*:com.*:org.junit.*:junit.*:"/>
|
||||
|
||||
<!-- build and distro settings -->
|
||||
<property name="jar.name" value="poi"/>
|
||||
<property name="build.site" location="build/tmp/site/build/site"/>
|
||||
@ -255,6 +266,13 @@ under the License.
|
||||
<pathelement location="${main.output.test.dir}"/>
|
||||
</path>
|
||||
|
||||
<path id="lib.jacoco">
|
||||
<fileset dir="lib">
|
||||
<include name="org.jacoco*.jar" />
|
||||
<include name="asm-all-4*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<!-- Prints POI's Ant usage help -->
|
||||
<target name="help" description="Prints Apache POI's Ant usage help">
|
||||
<echo>
|
||||
@ -316,6 +334,8 @@ under the License.
|
||||
<available file="${main.junit.jar}"/>
|
||||
<available file="${main.hamcrest.jar}"/>
|
||||
<available file="${main.ant.jar}"/>
|
||||
<available file="${asm.jar}"/>
|
||||
<available file="${jacoco.zip}"/>
|
||||
</and>
|
||||
<isset property="disconnected"/>
|
||||
</or>
|
||||
@ -349,6 +369,19 @@ under the License.
|
||||
<param name="sourcefile" value="${main.ant.url}"/>
|
||||
<param name="destfile" value="${main.ant.jar}"/>
|
||||
</antcall>
|
||||
<antcall target="downloadfile">
|
||||
<param name="sourcefile" value="${asm.url}"/>
|
||||
<param name="destfile" value="${asm.jar}"/>
|
||||
</antcall>
|
||||
<antcall target="downloadfile">
|
||||
<param name="sourcefile" value="${jacoco.url}"/>
|
||||
<param name="destfile" value="${jacoco.zip}"/>
|
||||
</antcall>
|
||||
<unzip src="${jacoco.zip}" dest=".">
|
||||
<patternset>
|
||||
<include name="lib/*.jar"/>
|
||||
</patternset>
|
||||
</unzip>
|
||||
</target>
|
||||
|
||||
<target name="check-ooxml-jars">
|
||||
@ -622,9 +655,77 @@ under the License.
|
||||
<delete file="${version.java}"/>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compile,test-main,test-scratchpad,test-ooxml,test-excelant"
|
||||
<target name="jacocotask" depends="">
|
||||
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
|
||||
<classpath refid="lib.jacoco"/>
|
||||
</taskdef>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compile,jacocotask,test-main,test-scratchpad,test-ooxml,test-excelant"
|
||||
description="Tests main, scratchpad and ooxml"/>
|
||||
<target name="test-all" depends="test,test-ooxml-lite"/>
|
||||
<target name="test-all" depends="test,test-ooxml-lite,testcoveragereport"/>
|
||||
|
||||
<target name="testcoveragereport" depends="jacocotask" description="create test-report" xmlns:jacoco="antlib:org.jacoco.ant" if="${coverage.enabled}">
|
||||
<delete dir="${coverage.dir}"/>
|
||||
<mkdir dir="${coverage.dir}"/>
|
||||
|
||||
<jacoco:report>
|
||||
<executiondata>
|
||||
<fileset dir="build">
|
||||
<include name="*.exec"/>
|
||||
</fileset>
|
||||
</executiondata>
|
||||
|
||||
<structure name="Apache POI">
|
||||
<group name="Main">
|
||||
<classfiles>
|
||||
<fileset dir="${main.output.dir}">
|
||||
<exclude name=""/>
|
||||
</fileset>
|
||||
</classfiles>
|
||||
<sourcefiles encoding="UTF-8">
|
||||
<fileset dir="${main.src}"/>
|
||||
</sourcefiles>
|
||||
</group>
|
||||
<group name="Scratchpad">
|
||||
<classfiles>
|
||||
<fileset dir="${scratchpad.output.dir}"/>
|
||||
</classfiles>
|
||||
<sourcefiles encoding="UTF-8">
|
||||
<fileset dir="${scratchpad.src}"/>
|
||||
</sourcefiles>
|
||||
</group>
|
||||
<group name="OOXML">
|
||||
<classfiles>
|
||||
<fileset dir="${ooxml.output.dir}">
|
||||
<exclude name=""/>
|
||||
</fileset>
|
||||
<fileset dir="${ooxml.lite.output.dir}">
|
||||
<exclude name="org/openxmlformats/**"/>
|
||||
<exclude name="schema*/**"/>
|
||||
</fileset>
|
||||
</classfiles>
|
||||
<sourcefiles encoding="UTF-8">
|
||||
<fileset dir="${ooxml.src}"/>
|
||||
<!--fileset dir="${ooxml.lite.src}"/-->
|
||||
</sourcefiles>
|
||||
</group>
|
||||
<group name="Excelant">
|
||||
<classfiles>
|
||||
<fileset dir="${excelant.output.dir}"/>
|
||||
</classfiles>
|
||||
<sourcefiles encoding="UTF-8">
|
||||
<fileset dir="${excelant.src}"/>
|
||||
</sourcefiles>
|
||||
</group>
|
||||
</structure>
|
||||
|
||||
<html destdir="${coverage.dir}"/>
|
||||
<xml destfile="${coverage.dir}/coverage.xml"/>
|
||||
</jacoco:report>
|
||||
|
||||
<echo message="Coverage results are available at coverage\index.html, coverage/coverage.xml" />
|
||||
</target>
|
||||
|
||||
<target name="-test-main-check">
|
||||
<uptodate property="main.test.notRequired" targetfile="${main.testokfile}">
|
||||
@ -634,7 +735,8 @@ under the License.
|
||||
</target>
|
||||
|
||||
<target name="test-main" unless="main.test.notRequired"
|
||||
depends="compile-main, -test-main-check">
|
||||
depends="compile-main, -test-main-check,jacocotask" xmlns:jacoco="antlib:org.jacoco.ant">
|
||||
<jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}" destfile="build/jacoco-main.exec">
|
||||
<junit fork="yes" forkmode="once" printsummary="yes" haltonfailure="${halt.on.test.failure}"
|
||||
failureproperty="main.test.failed" showoutput="true">
|
||||
<classpath refid="test.classpath"/>
|
||||
@ -643,6 +745,7 @@ under the License.
|
||||
<jvmarg value="-ea"/>
|
||||
<jvmarg value="-Xmx256m"/>
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${main.reports.test}">
|
||||
<fileset dir="${main.src.test}">
|
||||
<include name="**/${testpattern}.java"/>
|
||||
@ -652,6 +755,7 @@ under the License.
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</jacoco:coverage>
|
||||
<delete file="${main.testokfile}"/>
|
||||
<antcall target="-test-main-write-testfile"/>
|
||||
</target>
|
||||
@ -672,8 +776,9 @@ under the License.
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="test-scratchpad" depends="compile-main,compile-scratchpad,-test-scratchpad-check"
|
||||
unless="scratchpad.test.notRequired">
|
||||
<target name="test-scratchpad" depends="compile-main,compile-scratchpad,-test-scratchpad-check,jacocotask"
|
||||
unless="scratchpad.test.notRequired" xmlns:jacoco="antlib:org.jacoco.ant">
|
||||
<jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}" destfile="build/jacoco-scratchpad.exec">
|
||||
<junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
|
||||
failureproperty="scratchpad.test.failed">
|
||||
<classpath refid="test.scratchpad.classpath"/>
|
||||
@ -687,6 +792,7 @@ under the License.
|
||||
-->
|
||||
<jvmarg value="-Xmx256M"/>
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${scratchpad.reports.test}">
|
||||
<fileset dir="${scratchpad.src.test}">
|
||||
<include name="**/${testpattern}.java"/>
|
||||
@ -694,6 +800,7 @@ under the License.
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</jacoco:coverage>
|
||||
<delete file="${scratchpad.testokfile}"/>
|
||||
<antcall target="-test-scratchpad-write-testfile"/>
|
||||
</target>
|
||||
@ -709,9 +816,11 @@ under the License.
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<macrodef name="ooxml-test-runner">
|
||||
<macrodef name="ooxml-test-runner" xmlns:jacoco="antlib:org.jacoco.ant">
|
||||
<attribute name="classpath"/>
|
||||
<attribute name="type"/>
|
||||
<sequential>
|
||||
<jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}" destfile="build/jacoco-@{type}.exec">
|
||||
<junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
|
||||
failureproperty="ooxml.test.failed">
|
||||
<classpath refid="@{classpath}"/>
|
||||
@ -719,6 +828,7 @@ under the License.
|
||||
<jvmarg value="${poi.test.locale}"/>
|
||||
<!-- <jvmarg value="-ea"/> -->
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${ooxml.reports.test}">
|
||||
<fileset dir="${ooxml.src.test}">
|
||||
<include name="**/${testpattern}.java"/>
|
||||
@ -727,11 +837,12 @@ under the License.
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</jacoco:coverage>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<target name="test-ooxml" depends="compile-main,compile-ooxml,-test-ooxml-check" unless="ooxml.test.notRequired">
|
||||
<ooxml-test-runner classpath="test.ooxml.classpath"/>
|
||||
<target name="test-ooxml" depends="compile-main,compile-ooxml,-test-ooxml-check,jacocotask" unless="ooxml.test.notRequired">
|
||||
<ooxml-test-runner classpath="test.ooxml.classpath" type="ooxml"/>
|
||||
<delete file="${ooxml.testokfile}"/>
|
||||
<antcall target="-test-ooxml-write-testfile"/>
|
||||
</target>
|
||||
@ -754,10 +865,10 @@ under the License.
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="test-ooxml-lite">
|
||||
<target name="test-ooxml-lite" depends="jacocotask">
|
||||
<delete file="${ooxml.testokfile}"/>
|
||||
<echo message="Running ooxml tests against 'poi-ooxml-schemas'"/>
|
||||
<ooxml-test-runner classpath="ooxml-lite.classpath"/>
|
||||
<ooxml-test-runner classpath="ooxml-lite.classpath" type="ooxml-lite"/>
|
||||
</target>
|
||||
|
||||
<target name="-test-excelant-check">
|
||||
@ -771,8 +882,9 @@ under the License.
|
||||
<echo file="${excelant.testokfile}" append="false" message="testok"/>
|
||||
</target>
|
||||
|
||||
<target name="test-excelant" depends="compile-excelant,-test-excelant-check"
|
||||
unless="excelant.test.notRequired">
|
||||
<target name="test-excelant" depends="compile-excelant,-test-excelant-check,jacocotask"
|
||||
unless="excelant.test.notRequired" xmlns:jacoco="antlib:org.jacoco.ant">
|
||||
<jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}" destfile="build/jacoco-excelant.exec">
|
||||
<junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
|
||||
failureproperty="excelant.test.failed">
|
||||
<classpath refid="test.excelant.classpath"/>
|
||||
@ -780,12 +892,14 @@ under the License.
|
||||
<jvmarg value="${poi.test.locale}"/>
|
||||
<jvmarg value="-ea"/>
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${excelant.reports.test}">
|
||||
<fileset dir="${excelant.src.test}">
|
||||
<include name="**/${testpattern}.java"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</jacoco:coverage>
|
||||
<delete file="${excelant.testokfile}"/>
|
||||
<antcall target="-test-excelant-write-testfile"/>
|
||||
</target>
|
||||
|
@ -30,23 +30,19 @@ public class ExcelAntWorkbookUtilTestHelper extends ExcelAntWorkbookUtil {
|
||||
|
||||
public ExcelAntWorkbookUtilTestHelper(String fName) {
|
||||
super(fName);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ExcelAntWorkbookUtilTestHelper(Workbook wb) {
|
||||
super(wb);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDFFinder getFunctions() {
|
||||
// TODO Auto-generated method stub
|
||||
return super.getFunctions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormulaEvaluator getEvaluator(String excelFileName) {
|
||||
// TODO Auto-generated method stub
|
||||
return super.getEvaluator(excelFileName);
|
||||
}
|
||||
|
||||
|
@ -16,14 +16,21 @@
|
||||
==================================================================== */
|
||||
package org.apache.poi.ss.excelant.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.examples.formula.CalculateMortgageFunction;
|
||||
import org.apache.poi.ss.formula.udf.UDFFinder;
|
||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
public class TestExcelAntWorkbookUtil extends TestCase {
|
||||
|
||||
@ -44,6 +51,17 @@ public class TestExcelAntWorkbookUtil extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testWorkbookConstructor() throws InvalidFormatException, IOException {
|
||||
File workbookFile = new File(mortgageCalculatorFileName);
|
||||
FileInputStream fis = new FileInputStream(workbookFile);
|
||||
Workbook workbook = WorkbookFactory.create(fis);
|
||||
|
||||
fixture = new ExcelAntWorkbookUtilTestHelper( workbook ) ;
|
||||
|
||||
assertNotNull( fixture ) ;
|
||||
|
||||
}
|
||||
|
||||
public void testAddFunction() {
|
||||
fixture = new ExcelAntWorkbookUtilTestHelper(
|
||||
mortgageCalculatorFileName ) ;
|
||||
|
@ -46,6 +46,11 @@ public final class TestDocumentProperties
|
||||
|
||||
for (int x = 0; x < fields.length; x++)
|
||||
{
|
||||
// JaCoCo Code Coverage adds it's own field, don't look at this one here
|
||||
if(fields[x].getName().equals("$jacocoData")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fields[x].getType().isArray())
|
||||
{
|
||||
assertEquals(fields[x].get(_documentProperties),
|
||||
@ -53,6 +58,10 @@ public final class TestDocumentProperties
|
||||
}
|
||||
else
|
||||
{
|
||||
// ensure that the class was not changed/enhanced, e.g. by code instrumentation like coverage tools
|
||||
assertEquals("Invalid type for field: " + fields[x].getName(),
|
||||
"[B", fields[x].getType().getName());
|
||||
|
||||
byte[] buf1 = (byte[])fields[x].get(_documentProperties);
|
||||
byte[] buf2 = (byte[])fields[x].get(newDocProperties);
|
||||
Arrays.equals(buf1, buf2);
|
||||
|
Loading…
Reference in New Issue
Block a user