如何在没有运行测试的情况下获取所有标签和黄瓜场景 [英] How can gets all tags and cucumber scenarios without run tests

查看:19
本文介绍了如何在没有运行测试的情况下获取所有标签和黄瓜场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以某种方式获取我在项目中使用的所有标签的列表,并获取我在项目中没有运行测试的黄瓜场景的所有名称.有人可以帮我怎么做吗?

I would like somehow get list of all tags which I used in my project and get all names of cucumber scenarios which I have in my project without run tests. Could someone helps me how can I do this?

推荐答案

正如@mpkorstanje 所建议的,您可以为此创建一个自定义插件.

As suggested by @mpkorstanje you can create a custom plugin for this.

public class DryRunPlugin implements EventListener {

    @Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(TestCaseStarted.class, this::handleCaseStarted);
    }

    private void handleCaseStarted(TestCaseStarted event) {
        System.out.println(event.getTestCase().getUri());
        System.out.println(event.getTestCase().getName());
        System.out.println(event.getTestCase().getScenarioDesignation());
        event.getTestCase().getTags().stream().forEach(t -> 
        System.out.println(t.getName()));
    }

}

<小时>

@CucumberOptions(glue = "stepdef", plugin = {
        "formatter.DryRunPlugin" }, features = "src/test/resources/feature/", dryRun = true)

你会得到如下输出.

file:src/test/resources/feature/scenarios1.feature
Scenario 1
src/test/resources/feature/scenarios1.feature:5 # Scenario 1
@Feature
@ScenarioOne

示例功能文件.

@Feature
Feature: Scenario and Scenario Outline Combination

  @ScenarioOne
  Scenario: Scenario 1
    And this is "FIRST" step
    And this is "SECOND" step

这篇关于如何在没有运行测试的情况下获取所有标签和黄瓜场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆