TestNG取决于方法

时间:2018-12-22 19:46:21

标签: java selenium testng

package test;

import org.testng.annotations.Test;

public class Day3 {

    @Test
    public void webLoginCarLoan() {
        System.out.println("WebLoginCarLoan");
    }

    @Test
    public void mobileLoginCarLoan() {
        System.out.println("MobileLoginCarLoan");
    }

    @Test
    public void mobileSignoutCarLoan() {
        System.out.println("MobileSignoutCarLoan");
    }

    @Test(dependsOnMethods = { "webLoginCarLoan" })
    public void apiCarLoan() {
        System.out.println("LoginAPICarLoan");
    }

}

输出:

MobileLoginCarLoan
WebLoginCarLoan
MobileSignoutCarLoan
LoginAPICarLoan

为什么在输出中,WebLoginCarLoan优先于MobileSignoutCarLoan?

1 个答案:

答案 0 :(得分:0)

TestNG不能按照类中指出的顺序执行测试。如果您认为需要按指定的顺序执行测试/ @ Test方法,那么请使用优先级

 @Test(priority=1)

还如Mark所指出的:“我认为dependsOnMethods将确保webLoginCarLoan在apiCarLoan之前执行,但不会在其本身之后立即执行”

请参见Java Doc https://jitpack.io/com/github/cbeust/testng/master/javadoc/org/testng/annotations/Test.html#dependsOnMethods--