在所有黄瓜测试之后运行



在运行所有黄瓜测试后,是否有一种方法可以运行方法?

@后注释将在每个单独的测试后运行,对吗?我不是只能运行一次的东西,而是最后。

您可以使用标准的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");
    }
}

您可以做的是为TestRunFinished事件注册事件处理程序。为此,您可以创建一个自定义插件,该插件将在此事件中注册您的挂钩:

public class TestEventHandlerPlugin implements ConcurrentEventListener {
    @Override
    public void setEventPublisher(EventPublisher eventPublisher) {
        eventPublisher.registerHandlerFor(TestRunFinished.class, teardown);
    }
    private EventHandler<TestRunFinished> teardown = event -> {
        //run code after all tests
    };
}

,然后您必须注册插件:

  • 如果您正在运行Cucumber CLI,则可以使用-p/--plugin选项并通过Java类的完全合格名称:your.package.TestEventHandlerPlugin
  • 对于Junit Runner:
@RunWith(Cucumber.class)
@CucumberOptions(plugin = "your.package.TestEventHandlerPlugin") //set features/glue as you need.
public class TestRunner {
}

带有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");
}

cucumber是一个方案基础测试,您应该在 .feature文件中逐步编写自己的方案,并且这些步骤分别通过其步骤定义执行。

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

此外,对于您要在其他步骤之前要执行的内容,您应该在.feature文件中的所有步骤之前考虑一个步骤并在其步骤定义中开发它。

最新更新