1. junit 配置 @RunWith(Cucumber.class) @CucumberOptions(format ={"pretty","html:target/cucumber"}, features={"src/main/java/demoapp"},tags={"@third"}) public class test { } # language: zh-CN 功能:测试 @third 场景大纲:一些测试 假如 firstw "demo" 当 demoinfo <name> 那么 appdemo <info> 例子: |name| info| |first|dalong| |second|aaaaa| Feature:Belly @first ScenarioOutline: a few cukes Given firstw "demo" When demoinfo <name> Then appdemo <info> Examples: |name| info| |first|dalong| |second|aaaaa| publicclassMyStepdefs{ @Given("I have (\d+) cukes in my belly") publicvoid I_have_cukes_in_my_belly(int cukes){ System.out.format("Cukes: %n ", cukes); } @When("^I wait (\d+) hour$") publicvoid i_wait_hour(int arg1)throwsThrowable{ // Write code here that turns the phrase above into concrete actions thrownewPendingException(); } @Then("^dodemo$") publicvoid dodemo()throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("dodemo"); } @Given("^first "([^"]*)"$") publicvoid first(String arg1)throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("first"+": "+ arg1); } @Then("^my belly should growl$") publicvoid my_belly_should_growl()throwsThrowable{ // Write code here that turns the phrase above into concrete actions thrownewPendingException(); } @Given("^first demo$") publicvoid first_demo()throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("first_demo"); } @When("^user names$") publicvoid user_names(DataTable arg1)throwsThrowable{ // Write code here that turns the phrase above into concrete actions // For automatic transformation, change DataTable to one of // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>. // E,K,V must be a scalar (String, Integer, Date, enum etc) List<List<String>>list= arg1.raw(); System.out.println(list.get(0)); System.out.println(arg1.toString()); } @When("^demoinfo ([^"]*)$") publicvoid demoinfo_name(String name)throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println(name+"demoinfo_name"); //Assert.assertTrue(false); } @Then("^appdemo ([^"]*)$") publicvoid appdemo_info(String name )throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println(name+"appdemo_info"); } @When("^call me$") publicvoid call_me()throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("call me"); } @Then("^docall$") publicvoid docall()throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("docall"); } @Given("^firstw "([^"]*)"$") publicvoid firstw(String arg1)throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("firstw"); } @When("^demoinfo$") publicvoid demoinfo()throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("demoinfo"); } @When("^printinfos$") publicvoid printinfos(List<String> info)throwsThrowable{ // Write code here that turns the phrase above into concrete actions // For automatic transformation, change DataTable to one of // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>. // E,K,V must be a scalar (String, Integer, Date, enum etc) info.forEach(newConsumer<String>(){ @Override publicvoid accept(String t){ // TODO Auto-generated method stub System.out.println(t+"demo info"); } }); } @Then("^appdemo$") publicvoid appdemo()throwsThrowable{ // Write code here that turns the phrase above into concrete actions System.out.println("appdemo"); } } <dependencies> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version><!--$NO-MVN-MAN-VER$ --> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>