【问题标题】:How to run the cucumber test using gradle如何使用 gradle 运行黄瓜测试
【发布时间】:2015-04-07 20:25:37
【问题描述】:

我在 Gradle 中运行 Cucumber 测试时遇到问题。我正在使用 cucumber-jvm。

TestNGCucumberRunner 类使用@beforesuite@aftersuite 扩展AbstractTestNGCucumberTests 和testng 注释。

我通常通过右键单击在IntelliJ中运行TestNGCucumberRunner.java并成功运行。现在我想

  1. 在 gradle 中调用 TestNGCucumberRunner.java

  1. 调用gradle中的所有功能

我尝试将 TestNGCucumberRunner.java 作为 javaexec 执行,但失败了。

我尝试执行包中的所有功能文件。我也用过apply plugin: 'com.github.samueltbrown.cucumber'

【问题讨论】:

  • 下面是项目结构 这是脚本src-test-java-ctest-sampletest,TestNGCucumberRunner src-test-java-cpage-loginpage src-test-resources-navigation.feature 的文件夹结构
  • 你能编辑和发布一些你的 build.gradle 文件吗?
  • 感谢您的回复 :),我已经提取了上面的示例,它工作正常,将从一开始就执行相同的操作。我会这样做并让您知道结果。再次感谢
  • @user3350712 :您好,您关于通过 gradle 运行 Cucumber runner 的问题非常有趣。只是想知道并检查您是否能够破解我们查询的解决方案?如果是,那么我很想知道并查看您的 build.gradle 文件。你能分享一下吗?我会尝试一下,让你了解我的发现。

标签: java cucumber-jvm


【解决方案1】:

黄瓜文档不使用 gradle Test 任务类型,因此不存在某些集成(尤其是 Jacoco)。我仍在寻找一种方法来让测试任务在运行测试时执行 cucumbers main。

【讨论】:

    【解决方案2】:

    更新:

    我的设置使用不同的plugin,它支持场景的并行执行、更好的报告,并且仍在积极维护:

    build.gradle

    plugins {
      ...
      id "com.commercehub.cucumber-jvm" version "0.11"
    }
    
    addCucumberSuite 'cucumberTest'
    
    dependencies {
      ...
      cucumberTestCompile 'info.cukes:cucumber-java:1.2.5'  // or -java8 if you prefer lambda notation
    
    }
    

    目录结构

    └── src
        ├── cucumberTest
        │   ├── java
        │   │   └── package1 
        │           └──       <- Glue
        │   └── resources    
        │       └── package2 
        │           └──       <- Features
        ├── main
        │   └── java
        └── test
            └── java
    

    package1package2 名称(连同许多其他 options)可以在 build.gradle 文件中指定


    我的 previous 设置使用 cucumber for java 和 gradle。

    build.gradle

    plugins {
        id "java"
        id "com.github.samueltbrown.cucumber" version "0.9"
      }   
    
    dependencies {
        cucumberCompile 'info.cukes:cucumber-java:1.2.4'
    }
    
    cucumber {
        formats = ['pretty','junit:build/cucumber.xml']
    }
    

    目录布局

    └── src
        ├── cucumber
        │   ├── java         <- Glue
        │   └── resources    <- Features
        └── main
        │    └── java
        └── test
            └── java
    

    命令

    gradle cucumber
    

    【讨论】:

      【解决方案3】:

      我选择不使用com.github.samueltbrown.cucumberplugin,它最后一次更新是在 2015 年 8 月。相反,我创建了一个可以独立构建的“integrationTest”(黄瓜)源集。即,一个简单的gradle build 将构建testintegrationTest 源集。如果我只想运行集成测试,我可以运行gradle integrationTest -x test,或者我可以只运行gradle test -x integrationTest 的测试。

      我遵循的步骤在这里:http://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/

      但这里是总结:

      build.gradle

      sourceSets {
          integrationTest {
              java {
                  compileClasspath += main.output + test.output
                  runtimeClasspath += main.output + test.output
                  srcDir file('src/integrationTest/java')
              }
              resources.srcDir file('src/integrationTest/resources')
          }
      }
      
      //Ensure that the integrationTestCompile/integrationTestRuntime configuration contains the dependencies that are required to compile/run our unit tests.
      configurations {
          integrationTestCompile.extendsFrom testCompile
          integrationTestRuntime.extendsFrom testRuntime
      }
      
      task integrationTest(type: Test) {
          testClassesDir = sourceSets.integrationTest.output.classesDir
          classpath = sourceSets.integrationTest.runtimeClasspath
      
          // Gradle skips tasks whose input and output are up to date.
          // To ensure that your integration tests are run every time,
          // tell Gradle that the outputs of the integrationTest task should always be considered out of date.
          outputs.upToDateWhen { false }
      }
      
      // Ensure that our integration tests are run before the check task and that the check task fails the build if there are failing integration tests.
      // Ensure that our unit tests are run before our integration tests. This guarantees that our unit tests are run even if our integration tests fails.
      check.dependsOn integrationTest
      integrationTest.mustRunAfter test
      
      // Ensure that the HTML reports of unit and integration tests are created to different report
      // build/reports/integrationTest directory contains the HTML report that contains the test results of our integration tests.
      tasks.withType(Test) {
          reports.html.destination = file("${reporting.baseDir}/${name}")
      }
      
      def cucumberVersion = "1.2.4"
      
      dependencies {
          integrationTestCompile(
                  'info.cukes:cucumber-core:' + cucumberVersion,
                  'info.cukes:cucumber-java:' + cucumberVersion,
                  'info.cukes:cucumber-java:' + cucumberVersion,
                  'info.cukes:cucumber-junit:' + cucumberVersion,
                  'info.cukes:cucumber-spring:' + cucumberVersion,
                  'org.springframework:spring-beans:4.2.5.RELEASE'
          )
          integrationTestRuntime(
                  'org.springframework:spring-context:4.2.5.RELEASE',
                  'org.springframework:spring-test:4.2.5.RELEASE',
                  'org.springframework:spring-tx:4.2.5.RELEASE'
          )
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-13
        • 1970-01-01
        • 1970-01-01
        • 2020-12-19
        相关资源
        最近更新 更多