Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JUnit的build.xml文件在windows上没有问题,但在OS X上没有问题_Java_Macos_Ant_Junit_Build.xml - Fatal编程技术网

Java JUnit的build.xml文件在windows上没有问题,但在OS X上没有问题

Java JUnit的build.xml文件在windows上没有问题,但在OS X上没有问题,java,macos,ant,junit,build.xml,Java,Macos,Ant,Junit,Build.xml,我有一个问题,如果你能帮忙,我将不胜感激。 所以,我使用JUnit为ant构建了build.xml文件,在Windows操作系统上一切正常。但是,如果我将build.xml复制/粘贴到Mac OS上的同一个java项目中,它甚至无法构建或不运行测试 这是我的build.xml(我在build.xml中为在Mac上运行而更改的内容以注释和粗体显示): 建造datoteka za projekt Brojevi。 encoding=“UTF-8”debug=“on” debuglevel=“行、变

我有一个问题,如果你能帮忙,我将不胜感激。 所以,我使用JUnit为ant构建了build.xml文件,在Windows操作系统上一切正常。但是,如果我将build.xml复制/粘贴到Mac OS上的同一个java项目中,它甚至无法构建或不运行测试

这是我的build.xml(我在build.xml中为在Mac上运行而更改的内容以注释和粗体显示):


建造datoteka za projekt Brojevi。
encoding=“UTF-8”debug=“on”
debuglevel=“行、变量、源”
includeAntRuntime=“false”/
我不理解的是,如果我不将classpathref从“compile.path”更改为“test.path”(我在注释中添加的第四个也是最后一个内容),那么我得到的消息构建失败,并且包org.junit不存在。所以,如果我放置“test.path”,我得到了消息构建成功,但没有一个测试完成(JUnit生成的index.html表示没有测试完成,而且JUnit生成的xml文件是空的)。我必须改变什么才能让它工作? 谢谢你的帮助


编辑 终于solevd在寻找错误的5天后。当然是愚蠢的一个。我的测试文件和源代码在同一个目录中,而不是在测试目录中。谢谢evreyone的帮助,也很抱歉打扰您。

(这可能是一条评论,但我需要一些格式)

使用-
debug
选项运行ant。将输出重定向到文件。然后查找包含
'droping'
字符串的消息。这表明路径有问题,ant忽略了某些jar,因为找不到它们

其次,避免硬编码路径。
如果需要,可以从命令行属性中获取值或传入值。例如
-Djunit.home=/my/new/path

对于属性
junit.home
jacoco.home
您在OS X上使用了哪些值?/usr/local/junit和/usr/local/jacoco应该没问题,我认为@user2112471没有问题:很高兴看到问题得到解决。它是如何在一个平台而不是另一个平台上工作的?@Jayan:因为我不是Windows的忠实粉丝,所以我喜欢这种变化。我可以说,Mac是基于UNIX的,我喜欢它,我肯定会继续使用它。期待新的Java项目:)并没有真正解决我的问题,但通过这样做,我意识到它在哪里。谢谢:)
<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>