【问题标题】:Cucumber Runner doesn't load all feature files using KarateCucumber Runner 不会使用空手道加载所有功能文件
【发布时间】:2018-02-19 20:30:22
【问题描述】:

我正在使用空手道测试 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);
    }
}

谢谢:)

【问题讨论】:

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


    【解决方案1】:

    最简单的解释是@CucumberOptions中的tags有效果。尝试将其注释掉,然后重试。否则我无法从您提供的信息中得出任何结论。

    【讨论】:

    • 嗨,彼得,感谢您提供的出色工具和您的回复。我删除并重新创建了所有 5 个功能文件,解决了我的问题!
    • @NaelAbdeljawad great :) 通常不应该发生这种情况,因此请确保您的 maven pom.xml 具有文档中提到的调整,以防您将功能文件保存在 src/test/java 等中(p.s.如果有帮助,请投票/将答案标记为已接受)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多