日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

testNG之组测试

發布時間:2023/12/10 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 testNG之组测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

@Test(groups = {""})

  在執行測試用例的時候,往往一個功能依賴多個測試用例,比如流程的測試,那么這個時候就可以用到組測試,把流程涉及到測試用例都分到同一組里,按組執行即可。

  testNG的組通過@Test的groups屬性來指定的,一個方法可以屬于一個組(@Test(groups = {"checkintest"})),也可以屬于多個組(@Test(groups = {"functest","checkintest"}))。

  假設現在有3個java代碼,common.java、functionA.java、functionB.java,測試流程涉及到common.java中 login() 和?quit() 方法、functionA.java中的?testMethod1() 方法、functionB.java中的?testMethod3() 方法,那么可以將這4個方法分到同一組里functest,代碼如下:

?

common.java:

import org.testng.annotations.Test;public class common {@Test(groups = {"functest","checkintest"})public void login() {System.out.println("login");}@Test(groups = {"functest","checkintest"})public void quit() {System.out.println("quit");}@Test(groups = {"checkintest"})public void init() {System.out.println("init");} }

?

functionA.java:

import org.testng.annotations.Test;public class functionA {@Test(groups = {"functest"})public void testMethod1() {System.out.println("this is testMethod1"); } @Test(groups = {"functest2"})public void testMethod2() {System.out.println("this is testMethod2"); } }

?

functionB.java:

import org.testng.annotations.Test;public class functionB {@Test(groups = {"functest"})public void testMethod3() {System.out.println("this is testMethod3"); } @Test(groups = {"functest2"})public void testMethod4() {System.out.println("this is testMethod4"); } }

?

testng.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" ><suite name="Suite1" verbose="1" ><test name="Regression1" preserve-order="true"><groups><run><include name = "functest" /></run> </groups><classes><class name="common"></class><class name="functionA"></class><class name="functionB"></class></classes></test> </suite>

注意:testng.xml需要指定要測試的組(<groups>……</groups>)和組所在的class(<classes>……</classes>)

?

運行testng.xml,執行結果如下:

login quit this is testMethod1 this is testMethod3


@Test(priority = )

一般quit都是在流程的最后才執行,如何控制組里方法執行的順序呢?可以通過@Test的priority屬性,testNG按照priority從小到大的順序執行

修改common.java,在@Test中添加屬性priority = 1priority = 4

import org.testng.annotations.Test;public class common {@Test(groups = {"functest","checkintest"},priority = 1)public void login() {System.out.println("login");}@Test(groups = {"functest","checkintest"},priority = 4)public void quit() {System.out.println("quit");}@Test(groups = {"checkintest"})public void init() {System.out.println("init");} }

?

修改functionA.java,在@Test中添加屬性priority = 2

import org.testng.annotations.Test;public class functionA {@Test(groups = {"functest"},priority = 2)public void testMethod1() {System.out.println("this is testMethod1"); } @Test(groups = {"functest2"})public void testMethod2() {System.out.println("this is testMethod2"); } }

?

修改functionB.java,在@Test中添加屬性priority = 3

import org.testng.annotations.Test;public class functionB {@Test(groups = {"functest"}, priority = 3)public void testMethod3() {System.out.println("this is testMethod3"); } @Test(groups = {"functest2"})public void testMethod4() {System.out.println("this is testMethod4"); } }

?

再次運行testng.xml,執行結果如下:

login this is testMethod1 this is testMethod3 quit

?

如何只執行組里 testMethod1() 和 testMethod3() 方法,而不執行 login() 和 quit() 方法呢?

修改testng.xml,添加<exclude name="checkintest"></exclude>,排除在checkintest組里的方法

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" ><suite name="Suite1" verbose="1" ><test name="Regression1" preserve-order="true"><groups><run><include name = "functest" /><exclude name="checkintest"></exclude></run> </groups><classes><class name="common"></class><class name="functionA"></class><class name="functionB"></class></classes></test> </suite>

?

再次運行testng.xml,執行結果如下:

this is testMethod1 this is testMethod3

?



轉載于:https://www.cnblogs.com/yuan-yuan/p/4498134.html

總結

以上是生活随笔為你收集整理的testNG之组测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。