通过 Windows 命令行的 Cucumber (Java) 通过批处理工作,但不是 pom
Cucumber (Java) via Windows command line works via batch, but not pom
我正在 运行 通过 Windows 命令行上的 Cucumber For Java 书中的示例。我可以从 Windows 批处理文件中很好地执行它,但是当尝试从 Maven 执行它时,我得到 "No sources to compile" 和 "No tests to run"。 pom 中需要什么才能指向与批处理中相同的 classes/features?
完整输出:
[C:\data_jeffy\code\java\cucumber\learning_cucumber\first_taste\checkout]mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Checkout Groceries Example 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ checkout-groceries-example ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ checkout-groceries-example --
-
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platf
orm dependent!
[INFO] skip non existing resourceDirectory C:\data_jeffy\code\java\cucumber\learning_cucumber\first
_taste\checkout\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ checkout-groceries-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ checkout-groceries-ex
ample ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platf
orm dependent!
[INFO] skip non existing resourceDirectory C:\data_jeffy\code\java\cucumber\learning_cucumber\first
_taste\checkout\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ checkout-groceries-example
---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.2:test (default-test) @ checkout-groceries-example ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.727 s
[INFO] Finished at: 2015-05-10T13:45:48-04:00
[INFO] Final Memory: 8M/155M
[INFO] ------------------------------------------------------------------------
checkout/pom.xml
:
<!--
! Excerpted from "The Cucumber for Java Book",
! published by The Pragmatic Bookshelf.
! Copyrights apply to this code. It may not be used to create training material,
! courses, books, articles, and the like. Contact us if you are in doubt.
! We make no guarantees that this code is fit for any purpose.
! Visit http://www.pragmaticprogrammer.com/titles/srjcuc for more book information.
-->
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.claysnow</groupId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Checkout Groceries Example</name>
<artifactId>checkout-groceries-example</artifactId>
<properties>
<cucumber.version>1.2.0</cucumber.version>
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<argLine>-Duser.language=en</argLine>
<argLine>-Xmx1024m</argLine>
<argLine>-XX:MaxPermSize=256m</argLine>
<argLine>-Dfile.encoding=UTF-8</argLine>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
checkout/features/checkout.feature
:
Feature: Checkout
Scenario: Checkout a banana
Given the price of a "banana" is 40c
When I checkout 1 "banana"
Then the total price should be 40c
Scenario Outline: Checkout bananas
Given the price of a "banana" is 40c
When I checkout <count> "banana"
Then the total price should be <total>c
Examples:
| count | total |
| 1 | 40 |
| 2 | 80 |
Scenario: Two bananas scanned separately
Given the price of a "banana" is 40c
When I checkout 1 "banana"
And I checkout 1 "banana"
Then the total price should be 80c
Scenario: A banana and an apple
Given the price of a "banana" is 40c
When I checkout 1 "banana"
And I checkout 1 "apple"
Then the total price should be 65c
checkout/checkout.bat
:
@(
set JAR_DIR=C:\data_jeffy\code\java\cucumber\learning_cucumber\first_taste\checkout\jars\
set CLASSPATH=%JAR_DIR%gherkin-2.12.2.jar;%JAR_DIR%cucumber-jvm-deps-1.0.3.jar;%JAR_DIR%cucumber-java-1.2.2.jar;%JAR_DIR%cucumber-core-1.2.2.jar;%JAR_DIR%junit-4.11.jar;.
)
javac -cp %CLASSPATH% step_definitions/CheckoutSteps.java implementation/Checkout.java
@(
REM java -cp %CLASSPATH% cucumber.api.cli.Main --help
)
java -cp %CLASSPATH% cucumber.api.cli.Main -p progress --snippets camelcase -g step_definitions features
将 cucumber-jvm 与 Maven 一起使用时,项目需要遵守 Maven 约定,以便 cucumber-jvm 可以选取不同的文件。如果使用 maven-surefire-plugin
:
- 特征文件需要存放在
src/test/resources
;
- 步骤定义需要存储在
src/test/java
;
- 用
@RunWith(Cucumber.class)
注解的单元测试需要存储在 src/test/java
.
然后可以执行测试 运行 mvn test
。你可以查看 this example 我穿上了 github.
我正在 运行 通过 Windows 命令行上的 Cucumber For Java 书中的示例。我可以从 Windows 批处理文件中很好地执行它,但是当尝试从 Maven 执行它时,我得到 "No sources to compile" 和 "No tests to run"。 pom 中需要什么才能指向与批处理中相同的 classes/features?
完整输出:
[C:\data_jeffy\code\java\cucumber\learning_cucumber\first_taste\checkout]mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Checkout Groceries Example 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ checkout-groceries-example ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ checkout-groceries-example --
-
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platf
orm dependent!
[INFO] skip non existing resourceDirectory C:\data_jeffy\code\java\cucumber\learning_cucumber\first
_taste\checkout\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ checkout-groceries-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ checkout-groceries-ex
ample ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platf
orm dependent!
[INFO] skip non existing resourceDirectory C:\data_jeffy\code\java\cucumber\learning_cucumber\first
_taste\checkout\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ checkout-groceries-example
---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.2:test (default-test) @ checkout-groceries-example ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.727 s
[INFO] Finished at: 2015-05-10T13:45:48-04:00
[INFO] Final Memory: 8M/155M
[INFO] ------------------------------------------------------------------------
checkout/pom.xml
:
<!--
! Excerpted from "The Cucumber for Java Book",
! published by The Pragmatic Bookshelf.
! Copyrights apply to this code. It may not be used to create training material,
! courses, books, articles, and the like. Contact us if you are in doubt.
! We make no guarantees that this code is fit for any purpose.
! Visit http://www.pragmaticprogrammer.com/titles/srjcuc for more book information.
-->
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.claysnow</groupId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Checkout Groceries Example</name>
<artifactId>checkout-groceries-example</artifactId>
<properties>
<cucumber.version>1.2.0</cucumber.version>
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<argLine>-Duser.language=en</argLine>
<argLine>-Xmx1024m</argLine>
<argLine>-XX:MaxPermSize=256m</argLine>
<argLine>-Dfile.encoding=UTF-8</argLine>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
checkout/features/checkout.feature
:
Feature: Checkout
Scenario: Checkout a banana
Given the price of a "banana" is 40c
When I checkout 1 "banana"
Then the total price should be 40c
Scenario Outline: Checkout bananas
Given the price of a "banana" is 40c
When I checkout <count> "banana"
Then the total price should be <total>c
Examples:
| count | total |
| 1 | 40 |
| 2 | 80 |
Scenario: Two bananas scanned separately
Given the price of a "banana" is 40c
When I checkout 1 "banana"
And I checkout 1 "banana"
Then the total price should be 80c
Scenario: A banana and an apple
Given the price of a "banana" is 40c
When I checkout 1 "banana"
And I checkout 1 "apple"
Then the total price should be 65c
checkout/checkout.bat
:
@(
set JAR_DIR=C:\data_jeffy\code\java\cucumber\learning_cucumber\first_taste\checkout\jars\
set CLASSPATH=%JAR_DIR%gherkin-2.12.2.jar;%JAR_DIR%cucumber-jvm-deps-1.0.3.jar;%JAR_DIR%cucumber-java-1.2.2.jar;%JAR_DIR%cucumber-core-1.2.2.jar;%JAR_DIR%junit-4.11.jar;.
)
javac -cp %CLASSPATH% step_definitions/CheckoutSteps.java implementation/Checkout.java
@(
REM java -cp %CLASSPATH% cucumber.api.cli.Main --help
)
java -cp %CLASSPATH% cucumber.api.cli.Main -p progress --snippets camelcase -g step_definitions features
将 cucumber-jvm 与 Maven 一起使用时,项目需要遵守 Maven 约定,以便 cucumber-jvm 可以选取不同的文件。如果使用 maven-surefire-plugin
:
- 特征文件需要存放在
src/test/resources
; - 步骤定义需要存储在
src/test/java
; - 用
@RunWith(Cucumber.class)
注解的单元测试需要存储在src/test/java
.
然后可以执行测试 运行 mvn test
。你可以查看 this example 我穿上了 github.