How to run cucumber file from command line

后端 未结 2 1655
悲哀的现实
悲哀的现实 2020-12-11 02:39

I have cucumber feature file located at below location on my local:

C:\\ProjectWork\\Workspace\\Cucumber\\DIT_Cucumber\\src\\cucumber\\featureOne.feature


        
相关标签:
2条回答
  • 2020-12-11 03:08

    Cucumber with Java:

    Run Feature: java -cp "jars/*" cucumber.api.cli.Main -p pretty features

    compile Step Definition file: javac -cp "jars/*" step_definition/StepDef.java

    Run Scenario: java -cp "jars/*;." cucumber.api.cli.Main -p pretty -g step_definition features

    0 讨论(0)
  • 2020-12-11 03:15

    JUnit Approach

    If using JUnit, you can run the test the same way you would run a JUnit test on the command line:

    java -cp <classpath> org.junit.runner.JUnitCore com.example.test.RunCukesTest
    

    where RunCukesTest is the unit test that sets all the cucumber options, e.g.:

    package com.example.test;
    
    import org.junit.runner.RunWith;
    
    import cucumber.api.junit.Cucumber;
    import cucumber.api.CucumberOptions;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(plugin = "json:target/report.json")
    public class RunCukesTest {
    }
    

    Cucumber-jvm Approach

    You can also use cucumber-jvm on the command line:

    java -cp <classpath> cucumber.api.cli.Main \
       --glue com.example.test \
       --plugin pretty path/to/features
    

    Maven

    The challenge in both previous cases is to build the classpath and make sure all the dependencies are properly loaded, including your own classes and the feature files. An easier solution would be to use for example Maven to define all the deps; running the tests is then as simple as:

    mvn verify
    
    0 讨论(0)
提交回复
热议问题