[英]Cucumber Runner doesn't load all feature files using Karate
I'm using Karate for testing REST API, now I'm trying to run feature files in parallel:我正在使用 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");
}
}
The test runs only 3 feature files in parallel and doesn't run all 5 features.该测试仅并行运行 3 个功能文件,并没有运行所有 5 个功能。 I got this code from CucumberRunner.parallel function:我从 CucumberRunner.parallel 函数中得到了这个代码:
CucumberRunner runner = new CucumberRunner(this.getClass());
List<FeatureFile> featureFiles = runner.getFeatureFiles();
Then tried to load my feature files, the list size is 3, that means the function didn't load all features.然后尝试加载我的功能文件,列表大小为 3,这意味着该功能没有加载所有功能。 Any idea why this is happening?知道为什么会这样吗?
Note: all feature files under the same package.注意:同一个包下的所有功能文件。
Parallel() function code: 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);
}
}
Thanks :)谢谢 :)
The simplest explanation is that the tags
in the @CucumberOptions
is having an effect.最简单的解释是@CucumberOptions
中的tags
正在起作用。 Try commenting it out and try again.尝试将其注释掉,然后重试。 Else there is nothing I can make out from the information you have provided.否则,我无法从您提供的信息中看出任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.