简体   繁体   中英

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

I am using Java, Selenium, Maven, and TestNG to execute automated tests. I am using Jenkins to clone the GitHub repo and start the tests when a build is started. 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.

<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. 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.

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?

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?

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. I removed all groups from my testng.xml file. I then split my testng.xml file per application (one file per application). In my pom.xml, my surefire plugin looks like this...

<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. Worked perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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