博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TestNG的IAnnotationTransformer监听器详解
阅读量:4179 次
发布时间:2019-05-26

本文共 1012 字,大约阅读时间需要 3 分钟。

到目前为止(TestNG 6.9.10),TestNG提供了三个IAnnotationTransformer系列的监听器,这3个监听器的目的都是在TestNG执行过程中动态改变测试类中Annotation的参数。其区别在于不同的IAnnotationTransformer监听器,能够操作的Annotation不同,具体情况如下:

  • IAnnotationTransformer,操作@Test标注
  • IAnnotationTransformer2,操作@Configuration标注、@DataProvider标注和@Factory标注
  • IAnnotationTransformer3,操作@Listeners标注

下面以最常用的IAnnotationTransformer监听器为例,介绍具体用法。

1.定制监听器

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

注意:IAnnotationTransformer监听器接口只有一个方法,该方法的第一个参数为ITestAnnotation,指定了所能够操作的标注为@Test。

而对于IAnnotationTransformer2监听器接口,其中有3个重载方法,每个方法的第一个参数不同,分别为IConfigurationAnnotationIDataProviderAnnotationIFactoryAnnotation

对于IAnnotationTransformer3监听器接口,其中有一个重载方法,该方法的第一个参数为IListenersAnnotation,指定了所能够操作的标注为@Listeners。

2.启动监听器

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

转载地址:http://gslai.baihongyu.com/

你可能感兴趣的文章
如何防止sql注入
查看>>
springmvc传值
查看>>
在Eclipse中查看Android源码
查看>>
[转]C语言printf
查看>>
对话周鸿袆:从程序员创业谈起
查看>>
Mysql中下划线问题
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
vue项目打包后无法运行报错空白页面
查看>>
1136 . 欧拉函数
查看>>
面试题:强制类型转换
查看>>
Decorator模式
查看>>
Template模式
查看>>
Observer模式
查看>>
高性能服务器设计
查看>>
图文介绍openLDAP在windows上的安装配置
查看>>
Pentaho BI开源报表系统
查看>>
Pentaho 开发: 在eclipse中构建Pentaho BI Server工程
查看>>
android中SharedPreferences的简单例子
查看>>
android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
查看>>
andorid里关于wifi的分析
查看>>