我能为我的听众TestNG的? [英] Can I order my TestNG listeners?

查看:218
本文介绍了我能为我的听众TestNG的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个情况我需要启用/禁用测试的基础上,从我的一套文件来的参数(使用AnnotationTransformer监听器)(使用ISuiteListener监听器)。然而,当我尝试调用AnnotationTransformer之前阅读在我的套装文件中的参数,我不能这样做。

这并没有帮助:

 <听众preserve阶=真正的>
        <监听器类名=automation.test.SentinelSuiteListener/>
        <监听器类名=automation.test.AnnotationTransformer/>
< /听众>

此外,当我试图实现这两个接口在一起,AnnoataionTransformer即变换方法那张在onStart()方法之前:

 公共类AnnotationTransformer实现IAnnotationTransformer,ISuiteListener {    串currentRunModeInSuite;    @覆盖
    公共无效调用onStart(套装的iSuite){
        currentRunModeInSuite = suite.getParameter(currentRunMode);
    }    @覆盖
    公共无效变换(ITestAnnotation注释,类TestClass中,构造testConstructor,方法TestMethod的){
        的System.out.println(***审查测试用例:+ testMethod.getName());
        的for(int i = 0; I< annotation.getGroups()长;我++){
            的System.out.println(annotation.getGroups()[我]);
        }
        的System.out.println(currentRunModeInSuite);
    }
    @覆盖
    公共无效onFinish(套装的iSuite){
        // TODO自动生成方法存根
    }
}


解决方案

您看到的行为是因为TestNG的一步一步工作的预期之一。

首先,它查找测试和读他们的DATAS。你可以,如果你想改变他们,并触发它的目标 IAnnotationTransformer

然后,TestNG的运行套件/测试/类/方法,您可以通过与 ISuiteListener 否则被触发。

您需要的是 IMethodInstance 这是在运行中调用:的 http://testng.org/doc/documentation-main.html#methodinterceptors

据透露,在<听众> 节点不接受 preserve序属性。请参阅文档: http://testng.org/testng-1.0.dtd.php

I have a situation where I need to enable/disable tests(using AnnotationTransformer listener) based on the parameter coming from my suite files(using ISuiteListener listener). However, when I try to read the parameters in my suite file before calling AnnotationTransformer, I am not able to do so.

This does not help:

<listeners preserve-order="true">
        <listener class name="automation.test.SentinelSuiteListener" />
        <listener class-name="automation.test.AnnotationTransformer" />
</listeners>

Also, when I try to implement both these interfaces together, the method for AnnoataionTransformer i.e. transform goes before the onStart() method:

public class AnnotationTransformer implements IAnnotationTransformer, ISuiteListener {

    String currentRunModeInSuite;

    @Override
    public void onStart(ISuite suite) {
        currentRunModeInSuite = suite.getParameter("currentRunMode");
    }

    @Override
    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        System.out.println("***Test case under review : " + testMethod.getName());
        for(int i=0; i<annotation.getGroups().length;i++){
            System.out.println(annotation.getGroups()[i]);
        }
        System.out.println(currentRunModeInSuite);
    }  


    @Override
    public void onFinish(ISuite suite) {
        // TODO Auto-generated method stub
    }
} 

解决方案

The behavior you seen is the expected one because TestNG works step by step.

First, it looks for tests and reads their datas. You can be triggered if you want to change them and it's the goal of IAnnotationTransformer.

Then, TestNG runs suite/tests/classes/methods and you can be triggered by that with ISuiteListener or else.

What you need is IMethodInstance which is called during the run: http://testng.org/doc/documentation-main.html#methodinterceptors

Fyi, the <listeners> node doesn't accept preserve-order attribute. See the documentation: http://testng.org/testng-1.0.dtd.php

这篇关于我能为我的听众TestNG的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆