【发布时间】:2020-06-05 02:23:56
【问题描述】:
我是 Apache ant 的新手来构建项目。在我的项目中,我使用了 MySQL、junit 和 hibernate 库。我正在研究 bitbucket 管道,所以有些人建议使用 ant。所以我正在创建 build.xml 文件,其中的过程是干净的,构建,运行 junit 测试用例。我做了很多研究如何学习这些东西,但我被困在某个地方。我在清理目录和构建方面也很成功,但我坚持检查 junit 失败测试用例。我试图在 Eclipse 中运行这些测试用例,它显示测试用例失败,但如果我通过 ant 运行它总是说构建成功。我将提供我的项目结构。
+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>
It always gives me this output:-
clean:
[delete] Deleting directory F:\Repository\Agile\HiberTest\HTest\bin
init:
[mkdir] Created dir: F:\Repository\Agile\HiberTest\HTest\bin
[copy] Copying 1 file to F:\Repository\Agile\HiberTest\HTest\bin
build-project:
[echo] Hibernate test: F:\Repository\Agile\HiberTest\build.xml
[javac] Compiling 3 source files to F:\Repository\Agile\HiberTest\HTest\bin
junit:
BUILD SUCCESSFUL
Total time: 1 second
我想检查是否 junit 测试失败然后停止构建过程,如果全部通过且没有错误,然后我想创建可执行的 jar 文件
提前致谢
【问题讨论】:
-
我删除了我的答案,因为它不再有意义,因为您编辑了问题。
-
您好,我改变了,但没有任何效果。请您再次检查代码。谢谢
-
我不明白这个问题了。您删除了构建目标,但它仍然显示在输出中?是不是应该是的时候你得到了haltonfailure="no"?
-
对不起,我忘记将输出构建更改为我更改的 junit。我将 haltonfailure 更改为 yes 如果我的任何测试用例失败,我需要这些,然后我需要停止构建。谢谢@martin
-
问题解决了吗?
标签: java hibernate junit build ant