小编典典

如何在詹金斯上运行TestNG测试

jenkins

我正在尝试从Jenkins运行TestNG测试(在一个包含的Java项目中),但是没有运气。

似乎Jenkins的TestNG插件(https://wiki.jenkins-ci.org/display/JENKINS/testng-
plugin)仅发布TestNG测试的结果,但实际上不运行测试类…或我错了吗?

无论如何,我该如何在Jenkins的TestNG项目中实际运行TestNG测试,或者甚至有可能?例如,是否必须使用命令行语句或批处理文件(在Windows
Server 2008上)?

任何帮助,不胜感激。

PS
我尝试在Jenkins中输入一个用于该项目的构建后命令行以运行TestNG测试,但由于找不到TestNG的类路径而很难。我发布了一个有关无法从命令行运行TestNG的问题,因此我放弃了这条路线:


阅读 269

收藏
2020-07-25

共1个答案

小编典典

如上所述,请使用以下ant脚本运行TestNG单元测试。请调整以下代码以满足您的要求。

<?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插件/任务运行此脚本

2020-07-25