如何计算通过所有方案大纲的要素文件的数量?

时间:2018-07-23 16:54:07

标签: java cucumber cucumber-java

我是黄瓜新手。我正在使用Java代码/在团队城市建设中进行以下操作(即自动进行,无需人工干预)

  1. 我生成的特征文件最多包含三个方案大纲
  2. 我计算生成的功能文件的数量并运行功能文件
  3. 是否有内置的Cucumber标签或可用于计算所有通过的功能文件的内容?

预先感谢您的帮助

1 个答案:

答案 0 :(得分:0)

Custom formatter below will give the lists of feature files in which all steps have passed and also lists of feature files in which any step have failed. Implement the other methods with empty methods as required. Add this to the runner in the plugins options.

public class SuccessCounter implements Reporter, Formatter {

    private List<Feature> allScenarioPassedFeature;
    private List<Feature> anyScenarioFailedFeature;
    private boolean stepFailed;
    private Feature feature;

    public  SuccessCounter() {
        allScenarioPassedFeature = new ArrayList<Feature>();
        anyScenarioFailedFeature = new ArrayList<Feature>();
    }


    @Override
    public void result(Result arg0) {
        if(stepFailed==false && arg0.getStatus() != Result.PASSED)
            stepFailed = true;            
    }

    @Override
    public void close() {
        System.out.println("COUNTS");
        System.out.println("Passed - " + allScenarioPassedFeature.size());
        System.out.println("Failed - "+anyScenarioFailedFeature.size());
    }

    @Override
    public void eof() {
        if(stepFailed)
            anyScenarioFailedFeature.add(feature);
        else
            allScenarioPassedFeature.add(feature);
    }

    @Override
    public void feature(Feature arg0) {
        stepFailed = false;
        this.feature = arg0;
    }

}

Use at your own peril if u have parallel running.