Browse Source

Bugzilla #52151: added ant script to get JaCoCo code coverage

Patch by Mehdi Houshmand, applied with changes


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1203749 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Vincent Hennebert 12 years ago
parent
commit
07f082ad3d

+ 7
- 5
build.xml View File

@@ -151,7 +151,7 @@ list of possible build targets.
<property name="javac.source" value="1.5"/>
<property name="javac.target" value="1.5"/>
<property name="javac.fork" value="no"/>
<property name="junit.fork" value="on"/>
<property name="junit.fork" value="yes"/>
<property name="junit.haltonfailure" value="off"/>
<property name="javadoc.packages" value="org.apache.fop.*"/>
<property name="src.dir" value="${basedir}/src"/>
@@ -784,7 +784,8 @@ list of possible build targets.
</sequential>
</macrodef>
<target name="junit-all" depends="junit-compile, junit-transcoder, junit-layout-hyphenation, setup-xml-schema" description="Runs FOP's JUnit basic tests" if="junit.present">
<junit dir="${basedir}" haltonfailure="yes" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<junit dir="${basedir}" haltonfailure="yes" fork="${junit.fork}" forkmode="once"
errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="jawa.awt.headless" value="true"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
@@ -807,8 +808,8 @@ list of possible build targets.
<junit-run title="standard layout engine" testsuite="org.apache.fop.layoutengine.LayoutEngineTestSuite" outfile="TEST-layoutengine-standard"/>
</target>
<target name="junit-layout-hyphenation" depends="hyphenation-present, junit-compile" if="hyphenation.present" description="Runs FOP's JUnit hyphenation layout tests">
<property name="fop.layoutengine.testset" value="hyphenation"/>
<junit-run title="hyphenation layout engine" testsuite="org.apache.fop.layoutengine.LayoutEngineTestSuite" outfile="TEST-layoutengine-hyphenation"/>
<junit-run title="hyphenation layout engine" testsuite="org.apache.fop.layoutengine.HyphenationLayoutTestCase"
outfile="TEST-layoutengine-hyphenation"/>
</target>
<target name="junit-layout" depends="junit-layout-standard, junit-layout-hyphenation" description="Runs all FOP's JUnit layout tests"/>
<target name="junit-fotree" depends="junit-compile" description="Runs FOP's FO tree JUnit tests" if="junit.present">
@@ -851,7 +852,8 @@ list of possible build targets.
<junit-run title="render-pdf" testsuite="org.apache.fop.render.pdf.RenderPDFTestSuite" outfile="TEST-render-pdf"/>
</target>
<target name="junit-reduced" depends="junit-userconfig, junit-basic, junit-transcoder, junit-text-linebreak, junit-fotree, junit-render-pdf"/>
<target name="junit" depends="junit-all" description="Runs all of FOP's JUnit tests" if="junit.present">
<target name="junit" depends="junit-all" description="Runs all of FOP's JUnit tests"
if="junit.present">
<fail><condition><or><isset property="fop.junit.error"/><isset property="fop.junit.failure"/><not><isset property="hyphenation.present"/></not></or></condition>
NOTE:
**************************************************************************

+ 38
- 0
jacoco.xml View File

@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<project xmlns:jacoco="antlib:org.jacoco.ant" name="JaCoCo" default="coverage-report">
<import file="build.xml"/>
<property name="jacoco.report.dir" value="${build.dir}/report_jacoco"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath location="${jacocoant.jar}"/>
</taskdef>
<target name="test-coverage" depends="junit-compile, setup-xml-schema">
<jacoco:coverage destfile="${jacoco.report.dir}/jacoco.exec">
<junit dir="${basedir}" haltonfailure="yes" fork="on" forkmode="once">
<sysproperty key="jawa.awt.headless" value="true"/>
<classpath>
<path refid="standard-junit-classpath"/>
</classpath>
<batchtest>
<fileset dir="${build.unit.tests.dir}" includes="**/*TestCase.class"/>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="coverage-report" depends="test-coverage"
description="Runs JaCoCo for a code coverage report">
<jacoco:report>
<executiondata>
<file file="${jacoco.report.dir}/jacoco.exec"/>
</executiondata>
<structure name="Apache FOP">
<classfiles>
<fileset dir="${build.classes.dir}"/>
</classfiles>
<sourcefiles>
<fileset dir="${src.java.dir}"/>
</sourcefiles>
</structure>
<html destdir="${jacoco.report.dir}"/>
</jacoco:report>
</target>
</project>

+ 3
- 0
status.xml View File

@@ -60,6 +60,9 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
<action context="Code" dev="VH" type="add" fixes-bug="52151" due-to="Mehdi Houshmand">
Added ant script to get JaCoCo code coverage.
</action>
<action context="Code" dev="VH" type="add" fixes-bug="52136" due-to="Mehdi Houshmand">
Added to build file JUnit target that uses a regex to run all of the test cases. This
reduces the risk that some of them are omitted when building FOP.

+ 53
- 0
test/java/org/apache/fop/layoutengine/HyphenationLayoutTestCase.java View File

@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* $Id$ */

package org.apache.fop.layoutengine;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.junit.runners.Parameterized.Parameters;

/**
* Class for testing the FOP's hyphenation layout engine using testcases specified in XML
* files.
*/
public class HyphenationLayoutTestCase extends LayoutEngineTestCase {

/**
* Creates the parameters for this test.
*
* @return the list of file arrays populated with test files
* @throws IOException if an I/O error occurs while reading the test file
*/
@Parameters
public static Collection<File[]> getParameters() throws IOException {
return LayoutEngineTestUtils.getLayoutTestFiles("hyphenation-testcases");
}

/**
* Constructor
* @param testFile the file to test
*/
public HyphenationLayoutTestCase(File testFile) {
super(testFile);
}

}

+ 13
- 2
test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java View File

@@ -172,15 +172,26 @@ public final class LayoutEngineTestUtils {
* @return A collection of file arrays that contain the test files
*/
public static Collection<File[]> getLayoutTestFiles() {
TestFilesConfiguration.Builder builder = new TestFilesConfiguration.Builder();
String testSet = System.getProperty("fop.layoutengine.testset");
testSet = (testSet != null ? testSet : "standard") + "-testcases";
return getLayoutTestFiles(testSet);
}

/**
* This is a helper method that uses the standard parameters for FOP's layout engine tests,
* given a test set name returns a set of test files.
*
* @param testSetName the name of the test set
* @return A collection of file arrays that contain the test files
*/
public static Collection<File[]> getLayoutTestFiles(String testSetName) {
TestFilesConfiguration.Builder builder = new TestFilesConfiguration.Builder();

builder.testDir("test/layoutengine")
.singleProperty("fop.layoutengine.single")
.startsWithProperty("fop.layoutengine.starts-with")
.suffix(".xml")
.testSet(testSet)
.testSet(testSetName)
.disabledProperty("fop.layoutengine.disabled",
"test/layoutengine/disabled-testcases.xml")
.privateTestsProperty("fop.layoutengine.private");

Loading…
Cancel
Save