Cucumber(Java)通过Windows命令行通过批处理,但不是pom [英] Cucumber (Java) via Windows command line works via batch, but not pom

查看:835
本文介绍了Cucumber(Java)通过Windows命令行通过批处理,但不是pom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览 Cucumber for Java 书籍中的示例命令行。我可以从Windows批处理文件执行它,但是当尝试从Maven做它,我得到没有源码编译和没有测试运行。



完整输出:

pre> [C:\data_jeffy\code\java\cucumber\learning_cucumber\first_taste\checkout] mvn clean test
[INFO]扫描项目。 ..
[INFO]
[INFO] ---------------------------------- --------------------------------------
[INFO] Building Checkout Groceries Example 1.0
[INFO] ------------------------------------------- -----------------------------
[INFO]
[INFO] --- maven-clean-插件:2.5:clean(default-clean)@ checkout-groceries-example ---
[INFO]
[INFO] --- maven-resources-plugin: @ checkout-groceries-example -
-
[警告]使用平台编码(实际上是Cp1252)复制过滤的资源,即build是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] b $ b [INFO]
[INFO] --- maven-resources-plugin:2.6:testResources(default-testResources)@ checkout-groceries-ex
ample ---
[ ]使用平台编码(实际上是Cp1252)来复制过滤的资源,即build是platf
orm dependent!
[INFO]跳过不存在的资源目录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]源码编译
[INFO]
[INFO] --- maven-surefire-plugin:2.12.2:test(default-test)@ checkout-groceries-example ---
[ INFO]没有要运行的测试。
[INFO] ------------------------------------------- -----------------------------
[INFO] BUILD SUCCESS
[INFO] ----- -------------------------------------------------- -----------------
[INFO]总时间:0.727 s
[INFO]完成时间:2015-05-10T13:45:48-04 :00
[INFO] Final Memory:8M / 155M
[INFO] ---------------------------- --------------------------------------------

checkout / pom.xml

 <! -  
!摘自Cucumber for Java Book,
!出版的The Pragmatic Bookshelf。
!版权适用于此代码。它不能用于创建培训材料,
!课程,书籍,文章等。如果您有疑问,请与我们联系。
!我们不保证此代码适合任何目的。
!有关更多图书信息,请访问http://www.pragmaticprogrammer.com/titles/srjcuc。
- >
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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< / package>
< name> Checkout杂货示例< / 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

 功能:Checkout 
场景:结帐香蕉
鉴于香蕉的价格是40c
当我结帐1香蕉
那么总价格应该是40c
情景概述:结帐香蕉
考虑到香蕉的价格是40c
I checkout< count> banana
那么总价应该是< total> c
例子:
|计数|总|
| 1 | 40 |
| 2 | 80 |
情况:两个香蕉单独扫描
给定一个香蕉的价格是40c
当我结帐1香蕉
和我结帐1香蕉
那么总价应该是80c
场景:香蕉和苹果
鉴于香蕉的价格是40c
当我结帐1香蕉
和我结帐1apple
然后总价应为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


解决方案

当使用cucaven-jvm与Maven时,项目需要遵守Maven约定,以便cucumber-jvm可以拾取不同的文件。如果使用 maven-surefire-plugin




  • src / test / resources ;

  • 步骤定义需要存储在 src / test / java ;

  • 使用 @RunWith(Cucumber.class)注释注释的单元测试以存储在 src / test / java 中。



执行运行 mvn test 。您可以查看此示例我已加入github。


I'm running through the examples in the Cucumber For Java book on the Windows command line. I can execute it fine from a Windows batch file, but when attempting to do it from Maven, I'm getting "No sources to compile" and "No tests to run". What is needed in the pom to point to the same classes/features as in the batch?

Full output:

[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

解决方案

When using cucumber-jvm with Maven, the project needs to respect the Maven conventions so that cucumber-jvm can pick up the different files. If using maven-surefire-plugin:

  • The feature files need to be stored in src/test/resources;
  • The step definitions need to be stored in src/test/java;
  • The unit test(s) annotated with the @RunWith(Cucumber.class) annotation need to be stored in src/test/java.

Tests can then be executed running mvn test. You can check out this example I have put on github.

这篇关于Cucumber(Java)通过Windows命令行通过批处理,但不是pom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆