TestNg评估过程

问题描述 投票:-2回答:1

考虑下面两个我在testng中尝试过的代码,outuput是不同的,我无法理解为什么它先执行某些tc,然后再执行其他,testng如何决定先运行哪个tc]

代码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");
    }
}

输出:

3 e k 1 2 4

代码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");
    }
}

输出:

1

3

4

5

2

g

6

e

java testng
1个回答
0
投票
理想情况下,每个测试方法都应使用优先级,以确保顺序执行。
© www.soinside.com 2019 - 2024. All rights reserved.