TestNG 中不使用优先级的执行顺序 [英] Order of execution in TestNG without using priority

查看:22
本文介绍了TestNG 中不使用优先级的执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新版本的 TestNG,但仍然无法按照编写的顺序执行测试用例(避免使用优先级注释标签).

I am using latest version of TestNG but still not able execute testcases by the order it has been written(avoiding priority annotation tag).

import org.testng.annotations.Test;
public class NewTest {
@Test
public void b() {
    System.out.println("inside b method");
}
@Test
public void a() {
System.out.println("inside a method");
}
}

我也用过 IMethodInterceptor 但还是不行.

I have also used IMethodInterceptor but still no go.

在 testng.xml 中还添加了监听器:

in testng.xml also added listeners:

<listeners>
<listener class-name="testngdemo.PriorityInterceptor" />
</listeners>

但仍然得到以下输出

inside a method
inside b method

优先接口:

import java.lang.annotation.Retention; 
import java.lang.annotation.Target; 
import static java.lang.annotation.ElementType.METHOD; 
import static java.lang.annotation.ElementType.TYPE; 

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) 
@Target({METHOD, TYPE}) 
public @interface Priority { int value() default 0; }

推荐答案

如果你从 testng xml 运行你的测试用例,那么按照你想要的顺序包含你的测试方法,如下所示:

If you run your test cases from testng xml then include your test methods in the order you want like this:

<classes>

     ....
       ....
        <class name="Fully qualified class name without extension">
          <methods>
            <include name="method_1" />
            <include name="method_1" />
            .....
            .....
            <include name="method_N" />
          </methods>
        </class>

        <class name="test.Test2" />
     ....
    ....

</classes>

这篇关于TestNG 中不使用优先级的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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