如何在 Jenkins 上运行 TestNG 测试 [英] How to Run TestNG Tests on Jenkins

查看:53
本文介绍了如何在 Jenkins 上运行 TestNG 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 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?

非常感谢任何帮助.

P.S. 我尝试在 Jenkins 中为项目输入构建后命令行以运行 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:

如何从命令行运行 TestNG

推荐答案

如上所述,请使用以下 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆