【问题标题】:cucumber runner files is not able to pickup features/classes when run from maven从 maven 运行时,黄瓜运行程序文件无法获取功能/类
【发布时间】:2016-07-03 05:21:46
【问题描述】:

我可以毫无问题地运行我的黄瓜运行器文件(作为 JUnit)。测试已启动并运行良好。

但是当我通过 maven 运行时,虽然 maven 指向 Runner 文件,但无法执行测试。

请找到我的 maven 日志和 pom.xml 文件。有人可以帮我 pom.xml 中缺少什么吗?还是eclipse配置?

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building LinenHousePOC 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ LinenHousePOC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\Programming\Cucumber\LinenHousePOC\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ LinenHousePOC ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ LinenHousePOC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ LinenHousePOC ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ LinenHousePOC ---
[INFO] Surefire report directory: E:\Programming\Cucumber\LinenHousePOC\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running runners.RunnerTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@7f7052
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.041 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.463 s
[INFO] Finished at: 2016-07-03T10:45:17+05:30
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------

以下是我的 pom.xml:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>LinenHousePOC</groupId>
    <artifactId>LinenHousePOC</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.1.5</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.47.1</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.0</version>
        </dependency>
    </dependencies>
</project>

【问题讨论】:

  • 你能把你的黄瓜跑者课也发一下吗?
  • 您在 POM 中缺少构建步骤
  • 你的跑步者类文件名是什么?我没有看到您已经指出 maven POM 使用任何特定的运行程序文件在您的配置中运行。使用 include 标签指定运行器文件名。

标签: eclipse maven cucumber cucumber-jvm cucumber-junit


【解决方案1】:

更新您的 POM 版本!!

使用下面的配置并运行mvn clean verify。如果您不想并行运行测试,请删除 parallel、perCoreThreadCount 和 threadCountClasses 标签。确保更新正则表达式以匹配您的测试命名约定 **/Run*.java

         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <executions>
                    <execution>
                        <id>acceptance-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <outputEncoding>UTF-8</outputEncoding>
                            <parallel>classes</parallel>
                            <perCoreThreadCount>true</perCoreThreadCount>
                            <threadCountClasses>10</threadCountClasses>
                            <argLine>-Xmx1024m</argLine>
                            <argLine>-XX:MaxPermSize=256m</argLine>
                            <includes>
                                <include>**/Run*.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

【讨论】:

    【解决方案2】:

    从 IDE 执行测试不同于从命令行 (Maven) 执行测试。

    在 IDE 中,配置、上下文变量在我们调用测试时会自动初始化或选取。在 Maven 执行中,需要明确提及的参数很少。

    当您调用测试时:

    使用 Maven(命令行)执行测试

    mvn clean test -Dcucumber.options="--format json-pretty --glue classpath:src/test/resources"

    上述命令将设置 maven 需要从中选择测试以调用测试的粘合。

    此粘合信息与CucumberOptions 中的CucumberRunner.java 中作为输入传递的信息相同

    使用 Maven 执行测试(使用 Maven 配置文件)

    创建配置文件并将 cucumber.options 作为输入参数传递,如下所示:

    <profiles>
      <profile>
        <id>cucumber-tests</id>
        <properties>
          <cucumber.options>--glue src/test/resources</cucumber.options>
       </properties>
    
       . . . 
      </profile>
    </profiles>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-05
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      相关资源
      最近更新 更多