如何在Jenkins上运行TestNG测试 [英] How to Run TestNG Tests on Jenkins
问题描述
我正在尝试从Jenkins运行TestNG测试(在一个包含的Java项目中),但没有运气。
I'm trying to run TestNG tests (in a contained Java project) from Jenkins but having no luck.
好像Jenkins的TestNG插件( https://wiki.jenkins-ci.org/display/JENKINS/testng-plugin )只发布TestNG测试的结果,但实际上并没有运行测试类......还是我错了?
It appears as though the TestNG plugin for Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/testng-plugin) only publishes the results of TestNG tests, but doesn't actually run test classes... or am I wrong?
在任何情况下,我如何在Jenkins的TestNG项目中实际运行TestNG测试,或者甚至可能?例如,我是否必须使用命令行语句或批处理文件(在Windows Server 2008上)?
In any case, how do I actually run TestNG tests in a TestNG project with Jenkins, or is that even possible? Do I have to use a command line statement or batch file (on Windows Server 2008), for example?
任何帮助都非常感谢。
PS 我尝试在Jenkins中输入一个post-build命令行,以便项目运行TestNG测试,但是很难找到TestNG的类路径。我发布了一个关于从命令行运行TestNG的早期问题,我无法正常工作,所以我放弃了这条路线:
P.S. I tried entering a post-build command line in Jenkins for the project to run TestNG tests but had a hard time with class paths not being found for TestNG. I posted an earlier question about running TestNG from the command line which I couldn't get working, so I've given up on that route:
推荐答案
如上所述,请使用以下ant脚本运行TestNG单元测试。请调整以下代码以满足您的要求。
As commented above, please use the following ant script to run TestNG unit tests. Please tweak the below code to meet your requirements.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="Ant Play">
<property name="classes.dir" value="bin" />
<property name="report.dir" value="test-output" />
<path id="classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${basedir}\${classes.dir}"/>
</path>
<target name="init">
<mkdir dir="${classes.dir}"/>
<copy includeemptydirs="false" todir="${classes.dir}">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${classes.dir}"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-project" name="build"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" includeantruntime="false" destdir="${classes.dir}">
<src path="src"/>
<classpath refid="classpath"/>
</javac>
</target>
<target depends="build" name="runTests" description="Running tests" >
<echo>Running Tests...</echo>
<taskdef resource="testngtasks" classpathref="classpath"/>
<testng outputDir="${report.dir}"
haltonfailure="true"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter"
classpathref="classpath">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
<!--<classfileset dir="${classes.dir}" includes="**/*.class" />-->
</testng>
</target>
</project>
如果您遇到任何问题,请告诉我。顺便说一下,请使用Jenkins ant插件/任务来运行这个脚本
Let me know if you encounter any issues. BTW, please use the Jenkins ant plugin/task to run this script
这篇关于如何在Jenkins上运行TestNG测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!