Question

I have one question and would appreciate if you could help. So, I have build.xml file for ant using JUnit and everything goes fine on Windows OS. But if I copy/paste build.xml into the same java project on Mac OS it can't even build or it doesn't run tests.

Here is my build.xml ( things i changed in build.xml for running on Mac are in comments and bold):

<project name="Brojevi" default="jar" basedir="."
xmlns:jacoco="antlib:org.jacoco.ant">

<description>
Build datoteka za projekt Brojevi.
</description>


<property name="src" location="src"/>
<property name="src.java" location="${src}/main/java"/>
<property name="src.test" location="${src}/test/java"/>
<property name="build" location="build"/>
<property name="build.classes" location="${build}/classes"/>
<property name="build.test" location="${build}/test"/>
<property name="dist" location="dist"/>


<property name="junit.home" value="d:/usr/junit-4.11" /> <!--changed path -->
<property name="jacoco.home" value="d:/usr/jacoco-0.6.3" /> <!--changed path -->

<taskdef uri="antlib:org.jacoco.ant"
resource="org/jacoco/ant/antlib.xml">
<classpath path="${jacoco.home}/lib/jacocoant.jar"/>
</taskdef>


<path id="compile.path">
<pathelement location="${build.classes}"/>
</path>


<path id="test.path">
<path refid="compile.path"/>
<pathelement location="${build.test}"/>
<fileset dir="${junit.home}">
<include name="**/*.jar"/> <!--changed path -->
</fileset>
</path>

<target name="init">

<tstamp/>

<mkdir dir="${build}"/>
<mkdir dir="${dist}"/>
</target>

<target name="compile" depends="init"
description="Prevođenje izvornog koda">
<mkdir dir="${build.classes}"/>

<javac srcdir="${src.java}" destdir="${build.classes}"
classpathref="compile.path"  <!--changed to "test.path" -->
encoding="UTF-8" debug="on"
debuglevel="lines,vars,source"
includeAntRuntime="false" />
</target>

<target name="compile-tests" depends="compile"
description="Prevođenje izvornog koda testova">
<mkdir dir="${build.test}"/>

<javac srcdir="${src.test}" destdir="${build.test}"
classpathref="test.path"
encoding="UTF-8" debug="on"
debuglevel="lines,vars,source"
includeAntRuntime="false" />
</target>

<target name="run-tests" depends="compile-tests"
description="Izvođenje definiranih testova" >
<mkdir dir="${dist}/test-reports/xml"/>
<mkdir dir="${dist}/test-reports/html"/>
<mkdir dir="${dist}/test-reports/coverage"/>


<jacoco:coverage
destfile="${dist}/test-reports/xml/jacoco.exec">
<junit printsummary="yes" haltonfailure="yes"
fork="true" forkmode="once">
<classpath refid="test.path" />

<formatter type="plain"/>
<formatter type="xml"/>

<batchtest fork="yes" todir="${dist}/test-reports/xml">
<fileset dir="${src.test}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>


<junitreport todir="${dist}/test-reports/xml">
<fileset dir="${dist}/test-reports/xml">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${dist}/test-reports/html"/>
</junitreport>


<jacoco:report>
<executiondata>
<file file="${dist}/test-reports/xml/jacoco.exec"/>
</executiondata>

<structure name="${ant.project.name}">
<classfiles>
<fileset dir="${build.classes}"/>
<fileset dir="${build.test}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.java}"/>
<fileset dir="${src.test}"/>
</sourcefiles>
</structure>

<html destdir="${dist}/test-reports/coverage"/>

</jacoco:report>

</target>

<target name="clean"
description="Brisanje generiranog sadržaja" >

<delete dir="${build}" failonerror="false" />
<delete dir="${dist}" failonerror="false" />
</target>

</project>

what I don't underestand is that if I don't change classpathref from "compile.path" to "test.path" (fourth and last thing i put in comment), then i got message BUILD FAILED and that package org.junit does not exist. so if i put "test.path", i got message BUILD SUCCESSFUL, but none of the tests are done (index.html generated by JUnit says no tests are done, and also xml file generared by JUnit is empty). What do i have to change to make it work? Thanks for your help


EDIT Finally solevd after 5 days looking for mistake. Of course it was stupid one. My test file was in same directory with source code instead in test directory. Thanks evreyone for help and sorry for bothering you.

Was it helpful?

Solution

(This could have been a comment, but I need some formatting)

Run ant with -debug option. Redirect output to a file. Then look for messages with string containing 'dropping'. This indicate problem with paths and ant is ignoring certain jar as they are not found.

Secondly avoid hardcoding of path. If needed you can get values from environment variable or pass in command line property. For example -Djunit.home=/my/new/path

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top