jenkins通過maven指定testng的xml文件,並給testng代碼傳參


1.jenkins設置參數化構建,設置要傳的參數名和值

 

2.指定testng的xml文件,在jenkins的輸入以下

 

 

3.在pom.xml文件分別引用jenkins的參數,設置兩個property

 

  <xml.file>${env.xmlFileName}</xml.file>
        <testType>${env.testType}</testType>

 

4.在pom.xml中引用,maven-surefire-plugin的configuration添加如下

 

  <systemPropertyVariables>
                        <propertyName>${testType}}</propertyName>
                    </systemPropertyVariables>

                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/${xml.file}</suiteXmlFile>
                    </suiteXmlFiles>

 

5.在testng.xml中引用testType變量

   <parameter name="testType" value="${testType}"/>
    <test name="可用性測試">
        <classes>
        <class name="common.testsuites.TempTest"></class>
        </classes>
    </test>

6.新建測試類

/**
 * Created by qiaojiafei on 2018/3/31.
 */
public class TempTest {


    public String testType; @Parameters({ "testType" }) @BeforeMethod public void beforeMethod(String testType) { System.out.println("++++++------------------"+testType); this.testType = testType; } @BeforeClass public void beforeClass() { } @Test(groups = { "usabilitytest" }) public void tt() { System.out.println(testType); } }

7.執行jenkins,可以看到運行了指定的testng.xml文件,並且把testType給傳到了代碼中

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM