Cucumber Runner不会使用空手道加载所有功能文件

时间:2018-02-19 11:55:19

标签: java cucumber karma-runner cucumber-java karate

我使用Karate测试REST API,现在我尝试并行运行功能文件:

@CucumberOptions(tags = { "@someTest" })
public class ParallelTest {

@Test
public void testParallel() {
    KarateStats stats = CucumberRunner.parallel(getClass(), 5, 
    "target/surefire-reports/cucumber-html-reports");
    Assert.assertTrue(stats.getFailCount() == 0, "scenarios failed");
   }
}

测试仅并行运行3个功能文件,并且不运行所有5个功能。 我从CucumberRunner.parallel函数得到了这段代码:

CucumberRunner runner = new CucumberRunner(this.getClass());
List<FeatureFile> featureFiles = runner.getFeatureFiles();

然后尝试加载我的要素文件,列表大小为3,这意味着该功能没有加载所有功能。 知道为什么会这样吗?

注意:同一个软件包下的所有要素文件。

Parallel()函数代码:

  public static KarateStats parallel(Class clazz, int threadCount, String reportDir) {
    KarateStats stats = KarateStats.startTimer();
    ExecutorService executor = Executors.newFixedThreadPool(threadCount);
    CucumberRunner runner = new CucumberRunner(clazz);
    List<FeatureFile> featureFiles = runner.getFeatureFiles();
    List<Callable<KarateJunitFormatter>> callables = new ArrayList<>(featureFiles.size());
    int count = featureFiles.size();
    for (int i = 0; i < count; i++) {
        int index = i + 1;
        FeatureFile featureFile = featureFiles.get(i);
        callables.add(() -> {
            String threadName = Thread.currentThread().getName();
            KarateJunitFormatter formatter = getFormatter(reportDir, featureFile);
            logger.info(">>>> feature {} of {} on thread {}: {}", index, count, threadName, featureFile.feature.getPath());
            runner.run(featureFile, formatter);
            logger.info("<<<< feature {} of {} on thread {}: {}", index, count, threadName, featureFile.feature.getPath());
            formatter.done();
            return formatter;
        });
    }
    try {
        List<Future<KarateJunitFormatter>> futures = executor.invokeAll(callables);
        stats.stopTimer();
        for (Future<KarateJunitFormatter> future : futures) {
            KarateJunitFormatter formatter = future.get();
            stats.addToTestCount(formatter.getTestCount());
            stats.addToFailCount(formatter.getFailCount());
            stats.addToSkipCount(formatter.getSkipCount());
            stats.addToTimeTaken(formatter.getTimeTaken());
            if (formatter.isFail()) {
                stats.addToFailedList(formatter.getFeaturePath());
            }
        }
        stats.printStats(threadCount);
        return stats;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

谢谢:)

1 个答案:

答案 0 :(得分:1)

最简单的解释是tags中的@CucumberOptions有效。尝试将其评论出来并重试。另外,我从你提供的信息中找不到任何东西。