简体   繁体   English

如何指定要在Jenkins版本中运行的TestNG测试?

[英]How can I specify TestNG tests to run in Jenkins build?

I am using Java, Selenium, Maven, and TestNG to execute automated tests. 我正在使用Java,Selenium,Maven和TestNG执行自动测试。 I am using Jenkins to clone the GitHub repo and start the tests when a build is started. 我正在使用Jenkins克隆GitHub存储库并在构建开始时开始测试。 Currently I have tests for several applications in one project. 目前,我已经在一个项目中针对多个应用程序进行了测试。 My testng.xml file looks similar to below, "appOne" being one application and "appTwo" being another application, both running the "production" grouped tests. 我的testng.xml文件看起来与下面类似,“ appOne”是一个应用程序,“ appTwo”是另一个应用程序,均运行“生产”分组测试。

<test name="appOne">
    <groups>
        <run>
            <include name = "production" />
        </run>
    </groups>
</test>

<test name="appTwo">
    <groups>
        <run>
            <include name = "production" />
        </run>
    </groups>
</test>

Is there a way that I can pass these parameters through Jenkins so I can choose which apps to run with each Jenkins build. 有没有一种方法可以通过Jenkins传递这些参数,以便我可以选择要在每个Jenkins构建中运行的应用程序。 This scenario might also happen if I want to run all tests in the group "test." 如果我要运行“测试”组中的所有测试,也可能会发生这种情况。 Currently, I make the change in the testng.xml file and then commit my change to GitHub. 当前,我在testng.xml文件中进行更改,然后将更改提交到GitHub。

Or would it be better to have a separate project for each application, therefore a different build for each app using separate testng.xml files? 还是对每个应用程序有一个单独的项目,从而使每个应用程序使用不同的testng.xml文件使用不同的版本会更好?

Or would it be better to have a separate project for each application, therefore a different build for each app using separate testng.xml files? 还是对每个应用程序有一个单独的项目,从而使每个应用程序使用不同的testng.xml文件使用不同的版本会更好?

If this is a two different apps and there is no reasonable reason, would be better to separate job for each app in jenkins. 如果这是两个不同的应用程序,并且没有合理的原因,则最好在詹金斯中为每个应用程序分开工作。

@mbn217 gave me the answer in the comments. @ mbn217在评论中给了我答案。 I removed all groups from my testng.xml file. 我从testng.xml文件中删除了所有组。 I then split my testng.xml file per application (one file per application). 然后,我将每个应用程序的testng.xml文件拆分(每个应用程序一个文件)。 In my pom.xml, my surefire plugin looks like this... 在我的pom.xml中,我的surefire插件如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>${testngTarget}</suiteXmlFile>
        <suiteXmlFiles>
        <groups>${groupTarget}</groups>
    </configuration>
</plugin>

In Jenkins, I added that it was a parameterized build and added the names and default values of the parameters. 在Jenkins中,我添加了它是参数化的内部版本,并添加了参数的名称和默认值。 Worked perfectly. 工作完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM