简体   繁体   中英

Only run @Test2 when @Test1 passes

With TestTNG, how to only execute @Test2 when @Test1 passes?

public static void main (String args[]) {
    @beforemethod
    public static beforemethod() {
        /////
    }

    @test
    public static void firsttest() {
        \\\\
    }

    @test
    public static void secondtest() {
        \\\\\\
    }

    @test
    public static void thirdtest() {
        \\\\
    }

    @Aftermethod
    public static aftermethod() {
        \\\
    }

When firsttest() passes then secondtest() should execute, otherwise it should stop the execution.

How can we write this?

You can use the dependsOnMethods annotation like so:

@Test(dependsOnMethods = { "method1" } )

Then your test will execute only if method1 was successful (and always after it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM