英文:
TestNg evluation procedure
问题
Code 1:
package test;
import org.testng.annotations.Test;
public class day1 {
@Test
public void a() {
System.out.println("1");
}
@Test
public void c() {
System.out.println("3");
}
@Test
public void b() {
System.out.println("2");
}
@Test(dependsOnMethods = { "c" })
public void d() {
System.out.println("4");
}
@Test
public void k() {
System.out.println("k");
}
@Test
public void e() {
System.out.println("e");
}
}
output:
3 e k 1 2 4
Code 2:
package test;
import org.testng.annotations.Test;
public class day1 {
@Test
public void b() {
System.out.println("1");
}
@Test
public void f() {
System.out.println("2");
}
@Test
public void c() {
System.out.println("3");
}
@Test
public void d() {
System.out.println("4");
}
@Test
public void e() {
System.out.println("5");
}
@Test(dependsOnMethods = { "e" })
public void a() {
System.out.println("6");
}
@Test
public void g() {
System.out.println("g");
}
}
output:
1
3
4
5
2
g
6
e
英文:
Consider two below codes I tried in testng , outuput is different iam not getting why it is executing certain tc first and then other , how testng deciding which tc to run first
Code 1 :
package test;
import org.testng.annotations.Test;
public class day1 {
@Test
public void a()
{
System.out.println("1");
}
@Test
public void c()
{
System.out.println("3");
}
@Test
public void b()
{
System.out.println("2");
}
@Test(dependsOnMethods = { "c" })
public void d()
{
System.out.println("4");
}
@Test
public void k()
{
System.out.println("k");
}
@Test
public void e()
{
System.out.println("e");
}
}
output:
> 3 e k 1 2 4
Code 2:
package test;
import org.testng.annotations.Test;
public class day1 {
@Test
public void b()
{
System.out.println("1");
}
@Test
public void f()
{
System.out.println("2");
}
@Test
public void c()
{
System.out.println("3");
}
@Test
public void d()
{
System.out.println("4");
}
@Test
public void e()
{
System.out.println("5");
}
@Test(dependsOnMethods = { "e" })
public void a()
{
System.out.println("6");
}
@Test
public void g()
{
System.out.println("g");
}
}
output :
> 1
>
> 3
>
> 4
>
> 5
>
> 2
>
> g
>
> 6
>
> e
答案1
得分: 0
当您在TestNG中未指定priority
时,它会根据其内部逻辑决定优先级,该逻辑基于方法名称的字母顺序,而与它们在代码中的实现位置无关。
此外,如果一个测试方法(1)依赖于另一个测试方法(2),则只有在测试方法(1)通过时,测试方法(2)才会被执行。
理想情况下,您应该在每个测试方法中使用优先级以确保顺序执行。
英文:
When you do not specify priority
in testNG, it decides the priority by it's internal logic which is based on alphabetical order of their method names irrespective of their place of implementation in the code.
Also, if a Test Method(1) is dependent on other Test Method(2) then Test Method(2) will be executed only when Test Method(1) is passed.
Ideally you should use priority with each Test Method to ensure sequential execution.
专注分享java语言的经验与见解,让所有开发者获益!
评论