Cucumber-JVM Parallel Plugin问题:测试资源未生成且脚本不识别
Let's walk through the issues in your setup and get your parallel cucumber tests working properly. First, let's recap your situation:
- Maven build succeeds, but no test runners are generated by
cucumber-jvm-parallel-plugin - Cucumber scripts aren't being recognized, even after trying multiple fixes
First, Let's Look at Your Build Log & POM Issues
Build Log (for reference)
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ CucumberTest --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- cucumber-jvm-parallel-plugin:5.0.0:generateRunners (generateRunners) @ CucumberTest --- [INFO] Adding C:\Users\Bismillah\Documents\workspace-spring-tool-suite-4-4.9.0.RELEASE\CucumberTest\target\generated-test-sources\cucumber to test-compile source root [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ CucumberTest --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ CucumberTest --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to C:\Users\Bismillah\Documents\workspace-spring-tool-suite-4-4.9.0.RELEASE\CucumberTest\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ CucumberTest --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.204 s [INFO] Finished at: 2020-12-19T19:13:30+05:30 [INFO] ------------------------------------------------------------------------
Your Original POM (for reference)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.selenium.try</groupId> <artifactId>CucumberTest</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <compilerVersion>1.8</compilerVersion> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M3</version> <configuration> <parallel>methods</parallel> <threadCount>2</threadCount> <perCoreThreadCount>false</perCoreThreadCount> <testFailureIgnore>true</testFailureIgnore> <includes> <include>**/*IT.java</include> </includes> </configuration> </plugin> <plugin> <groupId>com.github.temyers</groupId> <artifactId>cucumber-jvm-parallel-plugin</artifactId> <version>5.0.0</version> <executions> <execution> <?m2e ignore?> <id>generateRunners</id> <phase>generate-test-sources</phase> <goals> <goal>generateRunners</goal> </goals> <configuration> <!-- Mandatory --> <!-- List of package names to scan for glue code. --> <glue>com.example</glue> <!-- These are optional, with the default values --> <!-- Where to output the generated tests --> <outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory> <!-- The directory, which must be in the root of the runtime classpath, containing your feature files. --> <featuresDirectory>src/test/resources/FeatureFiles/</featuresDirectory> <!-- Directory where the cucumber report files shall be written --> <cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir> <plugins> <plugin> <name>json</name> </plugin> </plugins> <tags> <tag>@tag1</tag> </tags> <!-- Generate TestNG runners instead of JUnit ones. --> <useTestNG>false</useTestNG> <!-- The class naming pattern to use. Only required/used if naming scheme is 'pattern'. --> <namingPattern>Parallel{c}IT</namingPattern> <!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per scenario. FEATURE generates a runner per feature. --> <parallelScheme>FEATURE</parallelScheme> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>4.2.3</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>4.2.6</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>4.2.6</version> </dependency> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>4.3.0</version> </dependency> </dependencies> </project>
Key Issues & Fixes
Mismatched Glue Package
This is the most critical issue: your plugin's<glue>is set tocom.example, but your project's groupId iscom.selenium.try. The glue path must point to the package where your Cucumber step definitions are stored. For example, if your steps are incom.selenium.try.stepdefs, update the glue line to:<glue>com.selenium.try.stepdefs</glue>If you have multiple glue packages, separate them with commas:
<glue>com.selenium.try.stepdefs, com.selenium.try.hooks</glue>Inconsistent Cucumber Dependency Versions
You're mixing different versions of Cucumber artifacts (4.2.3, 4.2.6, 4.3.0). This can cause hidden compatibility issues. Standardize on a single version (e.g., 4.2.6) for all Cucumber dependencies:<dependencies> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>4.2.6</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>4.2.6</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>4.2.6</version> </dependency> <!-- Remove cucumber-testng if you're using JUnit runners (useTestNG=false) --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>4.2.6</version> <scope>test</scope> </dependency> </dependencies>Also, since you're using JUnit runners (
useTestNG=false), you can optionally markcucumber-testngas test-scoped or remove it if you don't need TestNG support.Feature File Tag Filtering
Your plugin is configured to only generate runners for features tagged with@tag1. If your.featurefiles insrc/test/resources/FeatureFiles/don't have this tag, no runners will be created. Either:- Add
@tag1to your feature files, or - Remove the
<tags>section from the plugin configuration to include all features.
- Add
Surefire Plugin Parallel Configuration
You've set<parallel>methods</parallel>in Surefire, but since yourparallelSchemeisFEATURE(one runner per feature), it's more efficient to parallelize at the class level instead:<configuration> <parallel>classes</parallel> <threadCount>2</threadCount> <perCoreThreadCount>false</perCoreThreadCount> <testFailureIgnore>true</testFailureIgnore> <includes> <include>**/*IT.java</include> </includes> </configuration>Verify Generated Runners
After making these changes, runmvn clean verifyand check thetarget/generated-test-sources/cucumberdirectory. You should seeParallel*IT.javafiles generated here. If not:- Double-check your
featuresDirectorypath (ensure it's correct and contains.featurefiles) - Confirm your feature files are being copied to
target/test-classes/FeatureFiles/(your log says "Copying 2 resources"—verify these are your feature files)
- Double-check your
Final Checks
- Make sure your step definition classes are in the package specified in the
<glue>configuration - Clean your Maven project (
mvn clean) before rebuilding to avoid cached issues - Ensure your IDE (STS) recognizes the
target/generated-test-sources/cucumberdirectory as a test source root (the log says it's added, but sometimes IDEs need a refresh)
内容的提问来源于stack exchange,提问作者mahboob siddiqui

