How to run cucumber-jvm tests using Gradle

I am trying to get a project using the new Cucumber-jvm and Gradle system as my build system.

I used a sample Java code in the GitHub cucumber-jvm project ( https://github.com/cucumber/cucumber-jvm ).

My project is configured in IntelliJ, and the IDE can run the test.

However, Gradle does not find any tests to run. I know this because I violated the test, and Gradle said nothing. He also said nothing when he was working.

The class that he is trying to run is as follows:

import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Feature(value = "CarMaintenance.feature")
public class FuelCarTest {
}

I am new to both cucumbers and Gradle !!

+6
source share
3 answers

, Gradle, .

task executeFeatures(type: JavaExec, dependsOn: testClasses) {
    main = "cucumber.cli.Main"
    classpath += files(sourceSets.test.runtimeClasspath, file(webAppDir.path + '/WEB-INF/classes'))
    args += [ '-f', 'html:build/reports/cucumber', '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}

-f html

-g /

src/test/resources/features

testCompile 'org.mockito:mockito-all:1.9.5',
            'junit:junit:4.11',
            'org.hamcrest:hamcrest-library:1.3',
            'info.cukes:cucumber-java:1.0.14',
            'info.cukes:cucumber-junit:1.0.14',
            'info.cukes:cucumber-spring:1.0.14'

4.2.5

:

  • cli cucumber.api.cli.Main
  • -f ,

, build.gradle:

task executeFeatures(type: JavaExec, dependsOn: testClasses) {
    main = "cucumber.api.cli.Main"
    classpath += files(sourceSets.test.runtimeClasspath)
    args += [ '-g', 'uk.co.filmtrader', 'src/test/resources/features'] 
}
+4

build.gradle-
task RunCukesTest(type: Test) << {
include "RunCukesTest.class"
}

testCompile 'io.cucumber:cucumber-java:4.2.0'
testCompile 'io.cucumber:cucumber-junit:4.2.0'


your class - 
@RunWith(Cucumber.class)
@CucumberOptions(dryRun = false, strict = true, features = "src/test/resources", glue 
= "com.gradle.featuretests",monochrome = true)
public class RunCukesTest {
}

: - Gradle RunCukesTest

+1
build.gradle-
task RunCukesTest(type: Test) << {
include "RunCukesTest.class"
}

, . . ,

0

All Articles