问题描述
我的 TestNG 测试类中有多个侦听器,它使用 @Listeners
批注加载侦听器.
I have multiple listeners in my TestNG test class and its using @Listeners
annotations to load the listeners.
我的听众相互依赖,所以我需要确保 listener1
总是在 listener2
之前执行.
My listeners are dependent each others, so i need to make sure listener1
is executing before listener2
always.
当我们定义 listeners 数组时,我试图给出顺序.但似乎它不一致.有时 Listener2
在 Listener1
之前被调用.
I have tried to give the order when we defining the listeners array. but seems like its not consistent. Sometimes Listener2
is getting called before Listener1
.
@Listeners({ Listener1.class, Listener2.class })
如果有一些有关此问题解决方法的专业知识会很有帮助.
It will be helpful if some expertise on a workaround for this issue.
使用Java1.6/TestNg6.1.1
谢谢,
推荐答案
TestNG 不保证 Listeners
的顺序与作者 有没有办法定义两个不同Testng Listeners的运行顺序?因此,解决方法取决于您在侦听器中执行的操作,但很可能您必须更改这些逻辑(合并侦听器等).
TestNG does not guarantee Listeners
order as answered here by author Is there a way to define the runorder of two different Testng Listeners?So workaround depends on actions which you do in your listeners, but most probably you have to change these logic (merge listeners etc.).
这篇关于TestNG @Listeners 排序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!