Java 使用ApacheAnt成功构建但未运行junit文件
我是新加入ApacheAnt来构建这个项目的。在我的项目中,我使用了MySQL、junit和hibernate库。我正在研究bitbucket管道,所以有人建议使用ant。因此,我正在创建build.xml文件,其中的过程是干净的、构建的、运行的junit测试用例。我做了很多研究如何学习这些东西,但我被困在某个地方。我在清理目录和构建方面也取得了成功,但我一直在检查junit失败测试用例。我试图在eclipse中运行这些测试用例,它显示测试用例失败,但如果我运行ant,它总是说build successfully。我将提供我的项目结构Java 使用ApacheAnt成功构建但未运行junit文件,java,hibernate,junit,build,ant,Java,Hibernate,Junit,Build,Ant,我是新加入ApacheAnt来构建这个项目的。在我的项目中,我使用了MySQL、junit和hibernate库。我正在研究bitbucket管道,所以有人建议使用ant。因此,我正在创建build.xml文件,其中的过程是干净的、构建的、运行的junit测试用例。我做了很多研究如何学习这些东西,但我被困在某个地方。我在清理目录和构建方面也取得了成功,但我一直在检查junit失败测试用例。我试图在eclipse中运行这些测试用例,它显示测试用例失败,但如果我运行ant,它总是说build suc
+HiberTest
--HTest
--lib
--mysql
--junit
-- Hibernate..... so many library
--src
-com
-test
**so many junit files**
-com
-utils
**so many files**
--classpath
--.settings
--.project
**and many more files**
--build.xml
这是我的build.xml文件
<project basedir="." default="junit" name="Hibernate test">
<property name="debuglevel" value="source,lines,vars" />
<property name="src.dir" location="HTest/src" />
<property name="build.dir" location="HTest/bin" />
<property name="target" value="1.8" />
<property name="source" value="1.8" />
<property name="test.dir" value="HTest/bin/com/test" />
<path id="classpath">
<pathelement location="bin" />
<pathelement location="HTest/lib/junit3.8.1.jar" />
<pathelement location="HTest/lib/antlr-2.7.7.jar" />
<pathelement location="HTest/lib/byte-buddy-1.10.7.jar" />
<pathelement location="HTest/lib/classmate-1.5.1.jar" />
<pathelement location="HTest/lib/dom4j-2.1.1.jar" />
<pathelement location="HTest/lib/FastInfoset-1.2.15.jar" />
<pathelement location="HTest/lib/hibernate-commons-annotations-5.1.0.Final.jar" />
<pathelement location="HTest/lib/hibernate-core-5.4.11.Final.jar" />
<pathelement location="HTest/lib/istack-commons-runtime-3.0.7.jar" />
<pathelement location="HTest/lib/jandex-2.1.1.Final.jar" />
<pathelement location="HTest/lib/javassist-3.24.0-GA.jar" />
<pathelement location="HTest/lib/javax.activation-api-1.2.0.jar" />
<pathelement location="HTest/lib/javax.persistence-api-2.2.jar" />
<pathelement location="HTest/lib/jaxb-api-2.3.1.jar" />
<pathelement location="HTest/lib/jaxb-runtime-2.3.1.jar" />
<pathelement location="HTest/lib/jboss-logging-3.3.2.Final.jar" />
<pathelement location="HTest/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar" />
<pathelement location="HTest/lib/mysql-connector-java-5.1.48.jar" />
<pathelement location="HTest/lib/stax-ex-1.8.jar" />
<pathelement location="HTest/lib/txw2-2.3.1.jar" />
</path>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.dir}" />
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.launch" />
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" includeantruntime="false" source="${source}" target="${target}">
<src path="${src.dir}" />
<classpath refid="classpath" />
</javac>
</target>
<target name="junit" depends="build-project">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="classpath" />
<pathelement location="HTest/src/com/utils" />
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.dir}" includes="*.java" />
</batchtest>
</junit>
</target>
</project>
我想检查一下,如果junit测试失败,那么停止构建过程,如果所有测试都通过,那么我想创建可执行的jar文件
提前感谢构建从“构建”开始,层次结构从不调用junit。尝试更改:
<target depends="build-project" name="junit" />
Hello@Wender我已经更改了文件,但没有效果。如果你想看到我改变了文件,请看上面的代码。感谢@WenderI的解决方案,我想问题出在${test.dir}(value=“HTest/bin/com/test”)。此文件夹中没有Java文件,只有类。您可以将“bin”更改为src“dir”。我删除了我的答案,因为它不再有意义,因为您编辑了问题。您好,我更改了,但没有任何效果。请你再核对一下代码好吗。谢谢,我不明白这个问题了。您删除了构建目标,但它仍然显示在输出中?是否只是您在应该是的时候得到了haltonfailure=“no”?很抱歉,我忘了将输出构建更改为junit。我将haltonfailure改为yes我需要这些如果我的任何测试用例失败,那么我需要停止构建。。谢谢,问题解决了吗?
<target depends="build-project" name="junit" />