• Cucumber 使用例子


    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>
     
    

      

  • 相关阅读:
    常用的站内搜索技术比较
    .NET中读取csv文件内容
    C#编码规范
    处理模型——检测光标是否在模型上
    数据库如何规范命名
    处理顶点——绘制三角形,线和点
    处理模型——根据地形正确倾斜模型
    处理顶点——使用索引移除冗余顶点
    处理顶点——在三角形上添加纹理
    处理模型——通过定义一个自定义的TypeWriter和TypeReader将多个对象存储在Tag属性中
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/6339408.html
Copyright © 2020-2023  润新知