Cucumber Runner 不会使用空手道加载所有功能文件
Cucumber Runner doesn't load all feature files using 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);
}
}
谢谢:)
最简单的解释就是@CucumberOptions
里面的tags
有效果。尝试将其注释掉,然后重试。否则根据你提供的信息我什么也搞不出来。
我正在使用 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);
}
}
谢谢:)
最简单的解释就是@CucumberOptions
里面的tags
有效果。尝试将其注释掉,然后重试。否则根据你提供的信息我什么也搞不出来。