如何使用 JUnit 设置 Jenkins [英] How to setup Jenkins with JUnit

查看:41
本文介绍了如何使用 JUnit 设置 Jenkins的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个通常从 Eclipse 运行的 JUnit 测试套件.我们最近开始了一个尝试获得更好的开发环境的过程.作为其中的一部分,我们已经开始在 Jenkins 中构建我们的项目.如果可以在我们的构建过程中运行 JUnit 测试套件,我们也希望如此.为此,我认为我们需要一种从命令行执行测试套件的方法,以便我们可以将它们集成到 Jenkins 中并解析它们的输出.

We have a JUnit test suite that we usually run from Eclipse. We have recently started a process of trying to get a better development environment. As part of this we have started building our project in Jenkins. We would also like it if it was possible to run theJUnit test suite during our build. To do this I think we need a way to execute the test suite from command line so that we can integrate them in Jenkins and parse their output.

我们如何设置 Jenkins 来运行我们的测试?

How can we set up Jenkins to run our tests?

推荐答案

您可以在构建期间创建一个 junit ant 任务,并让 Jenkins 运行该任务

You could create a junit ant task during your build and let Jenkins run that task

以下是我们在项目中使用的一些行.这里启动一个名为 AllNonGWTTestCaseTests

Here are some lines we used on a project. Here launching a suite called AllNonGWTTestCaseTests

<target name="runTests" description="Run JUnit tests">
    <junit printsummary="yes" dir="test-classes" fork="true">
        <classpath>
            <pathelement location="inst-classes" />
        </classpath>
        <test name="xxx.AllNonGWTTestCaseTests" haltonfailure="no" outfile="result">
            <formatter type="xml" />
        </test>
    </junit>
</target>

构建此文件将创建文件 result.xml.这配置了一个蚂蚁任务.Jenkins 可以启动这个蚂蚁任务.看看你的项目配置.部分 Build >蚂蚁任务.然后在 Post-build Actions 中设置 xml 文件的路径:result.xml

Building this will create the file result.xml. That configures an ant task. Jenkins can launch this ant task. Take a look at your project configuration. Section Build > Ant task. Then in Post-build Actions just set the path to the xml file : result.xml

这应该使 Jenkins 运行测试套件作为构建后操作.

This should make Jenkins run the test suite as a post build action.

这篇关于如何使用 JUnit 设置 Jenkins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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