如何在 Jenkins 构建中将 TestNG 测试指定为 运行?

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

我正在使用 Java、Selenium、Maven 和 TestNG 来执行自动化测试。我正在使用 Jenkins 克隆 GitHub 存储库并在构建开始时开始测试。目前我在一个项目中测试了多个应用程序。我的 testng.xml 文件看起来类似于下面,"appOne" 是一个应用程序,"appTwo" 是另一个应用程序,两者都 运行 宁 "production" 分组测试。

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

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

有没有一种方法可以让我通过 Jenkins 传递这些参数,这样我就可以在每次 Jenkins 构建时选择要 运行 的应用程序。如果我想 运行 组 "test." 中的所有测试,也可能会发生这种情况。目前,我在 testng.xml 文件中进行更改,然后将更改提交到 GitHub。

或者为每个应用程序创建一个单独的项目,从而使用单独的 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?

如果这是两个不同的应用程序并且没有合理的理由,最好在 jenkins 中为每个应用程序分开工作。

@mbn217 在评论里给了我答案。我从 testng.xml 文件中删除了所有组。然后我将我的 testng.xml 文件拆分为每个应用程序(每个应用程序一个文件)。在我的 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>

在Jenkins中,我添加了它是参数化构建,并添加了参数的名称和默认值。完美运行。