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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

extjs 方法执行顺序_TestNG之注解变压器amp;方法拦截器

發布時間:2024/7/23 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 extjs 方法执行顺序_TestNG之注解变压器amp;方法拦截器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? 一.注解變壓器

??? TestNG允許在執行期間修改所有注解的內容。當源代碼中的注解大部分是正確的,但是有一些時刻你想要重寫他們的值時,這個是非常有用的。

? ? 可以使用注解變壓器實現。

? ? 注解變壓器是一個實現了接口的類:

public interface IAnnotationTransformer { /** * This method will be invoked by TestNG to give you a chance * to modify a TestNG annotation read from your test classes. * You can change the values you need by calling any of the * setters on the ITest interface. * * Note that only one of the three parameters testClass, * testConstructor and testMethod will be non-null. * * @param annotation The annotation that was read from your * test class. * @param testClass If the annotation was found on a class, this * parameter represents this class (null otherwise). * @param testConstructor If the annotation was found on a constructor, * this parameter represents this constructor (null otherwise). * @param testMethod If the annotation was found on a method, * this parameter represents this method (null otherwise). */ public void transform(ITest annotation, Class testClass, Constructor testConstructor, Method testMethod);}

? ? 就像所有其他的TestNG監聽者,你可以在命令行或使用ant來定義這個類:

java org.testng.TestNG -listener MyTransformer testng.xml

? ? 或編程式方式:

TestNG tng = new TestNG();tng.setAnnotationTransformer(new MyTransformer());// ...

? ? 當調用transform()方法時,可以調用ITest測試參數上任何設置方法來修改其值,然后再繼續測試。

? ? 例如,下面是一個如何重寫屬性的調用次數的例子,但是僅在測試類的測試方法的invoke()上:

public class MyTransformer implements IAnnotationTransformer { public void transform(ITest annotation, Class testClass, Constructor testConstructor, Method testMethod){ if ("invoke".equals(testMethod.getName())) { annotation.setInvocationCount(5); } }}

?? ?IAnnotationTransfomer只允許修改@Test注解,如果需要修改其他TestNG注解(配置注解,如@Factory或@DataProvider),需要使用IAnnotationTransformer2。

????二.方法攔截器

? ? 一旦TestNG計算出測試方法的調用順序,這些方法將被分成兩組:

? ? 1)方法按照順序執行,這些都是有依賴項或被依賴項的所有測試方法,這些測試方法將會按照特定的順序執行。

? ? 2)方法沒有特定的執行順序,這些都是不屬于第一類的方法。這些測試方法的運行順序是隨機的,每次運行時的順序都可能會不同(默認情況下,TestNG將按照類對測試方法進行分組)。

? ? 為了更好的控制第二類方法的執行,TestNG定義了下面這些接口:

public interface IMethodInterceptor { List intercept(List methods, ITestContext context);}

? ? 參數中傳遞的方法列表是可以按照任何順序運行的所有方法。攔截器將會返回一個類型的IMethodInstance列表,可以是以下任意一種:

? ? 1)一個更小的IMethodInstance對象列表。

? ? 2)一個更大的IMethodInstance對象列表。

? ? 3)一旦已定義了攔截器,就將它傳遞給TestNG作為一個監聽者,例如:

java -classpath "testng-jdk15.jar:test/build" org.testng.TestNG -listener test.methodinterceptors.NullMethodInterceptor

???-testclass test.methodinterceptors.FooTest

? ? 有關ant的有效語法,可以參考ant文檔中的listeners屬性。

? ? 例如,下面是一個方法攔截器,它將對方法重新排序,以便始終首先運行屬于組“fast”的測試方法:

public Listintercept(List methods, ITestContext context) { List result = new ArrayList(); for (IMethodInstance m : methods) { Test test = m.getMethod().getConstructorOrMethod().getAnnotation(Test.class); Set groups = new HashSet(); for (String group : test.groups()) { groups.add(group); } if (groups.contains("fast")) { result.add(0, m); } else { result.add(m); } } return result;}

總結

以上是生活随笔為你收集整理的extjs 方法执行顺序_TestNG之注解变压器amp;方法拦截器的全部內容,希望文章能夠幫你解決所遇到的問題。

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