如何在没有运行测试的情况下获取所有标签和黄瓜方案
问题描述:
我想以某种方式获取我在项目中使用的所有标签的列表,并获取我的项目中没有运行测试的所有黄瓜方案的名称.有人可以帮我怎么做吗?
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