所有黄瓜测试后运行

问题描述 投票:3回答:3

有没有办法在所有黄瓜测试运行后运行一个方法?

@After注释将在每次测试后运行,对吗?我不想只运行一次,但最后一次。

java testing automated-tests cucumber
3个回答
4
投票

您可以使用标准的JUnit注释。

在你的跑步者课上写下类似的东西:

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"html:target/cucumber-html-report", "json-pretty:target/cucumber-json-report.json"})
public class RunCukesTest {

    @BeforeClass
    public static void setup() {
        System.out.println("Ran the before");
    }

    @AfterClass
    public static void teardown() {
        System.out.println("Ran the after");
    }
}

1
投票

使用TestNG套件功能也可以。

@BeforeSuite
public static void setup() {
    System.out.println("Ran once the before all the tests");
}

@AfterSuite
public static void cleanup() {
    System.out.println("Ran once the after all the tests");
}

-3
投票

黄瓜是一个场景基础测试,你应该逐步在.feature文件中编写自己的场景,这些步骤分别由它们的步骤定义执行。

因此,如果您希望在所有步骤之后发生某些事情,则应在最后一步中编写它并在其步骤定义中开发此步骤。

此外,对于您希望在其他步骤之前执行的操作,您应该在.feature文件中的所有步骤之前考虑一个步骤,并在其步骤定义中进行开发。

© www.soinside.com 2019 - 2024. All rights reserved.