I'm using Karate for testing REST API, now I'm trying to run feature files in parallel:
@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. I got this code from CucumberRunner.parallel function:
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. Any idea why this is happening?
Note: all feature files under the same package.
Parallel() function code:
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 :)