gpt4 book ai didi

java - TestNG 中不使用优先级的执行顺序

转载 作者:行者123 更新时间:2023-11-28 21:26:15 25 4
gpt4 key购买 nike

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

enter image description here

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 但还是不行。

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

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

但仍然得到以下输出

inside a method
inside b method

优先接口(interface):

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 运行测试用例,则按照您想要的顺序包含您的测试方法,如下所示:

<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>

关于java - TestNG 中不使用优先级的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40105037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com