首页 > 其他 > 详细

Cucumber 使用例子

时间:2017-01-22 09:46:42      阅读:608      评论:0      收藏:0      [点我收藏+]
1. junit  配置
  1. @RunWith(Cucumber.class)
  2. @CucumberOptions(format ={"pretty","html:target/cucumber"},
  3. features={"src/main/java/demoapp"},tags={"@third"})
  4. publicclass test {
  5.  
  6.  
  7.  
  8.  
  9. }
  1. # language: zh-CN
  2. 功能:测试
  3. @third
  4. 场景大纲:一些测试
  5. 假如 firstw "demo"
  6. demoinfo <name>
  7. 那么 appdemo <info>
  8. 例子:
  9. |name| info|
  10. |first|dalong|
  11. |second|aaaaa|
  1. Feature:Belly
  2. @first
  3. ScenarioOutline: a few cukes
  4. Given firstw "demo"
  5. When demoinfo <name>
  6. Then appdemo <info>
  7. Examples:
  8. |name| info|
  9. |first|dalong|
  10. |second|aaaaa|
  1. publicclassMyStepdefs{
  2. @Given("I have (\\d+) cukes in my belly")
  3. publicvoid I_have_cukes_in_my_belly(int cukes){
  4. System.out.format("Cukes: %n\n", cukes);
  5. }
  6. @When("^I wait (\\d+) hour$")
  7. publicvoid i_wait_hour(int arg1)throwsThrowable{
  8. // Write code here that turns the phrase above into concrete actions
  9. thrownewPendingException();
  10. }
  11. @Then("^dodemo$")
  12. publicvoid dodemo()throwsThrowable{
  13. // Write code here that turns the phrase above into concrete actions
  14. System.out.println("dodemo");
  15. }
  16. @Given("^first \"([^\"]*)\"$")
  17. publicvoid first(String arg1)throwsThrowable{
  18. // Write code here that turns the phrase above into concrete actions
  19. System.out.println("first"+": "+ arg1);
  20. }
  21. @Then("^my belly should growl$")
  22. publicvoid my_belly_should_growl()throwsThrowable{
  23. // Write code here that turns the phrase above into concrete actions
  24. thrownewPendingException();
  25. }
  26. @Given("^first demo$")
  27. publicvoid first_demo()throwsThrowable{
  28. // Write code here that turns the phrase above into concrete actions
  29. System.out.println("first_demo");
  30. }
  31. @When("^user names$")
  32. publicvoid user_names(DataTable arg1)throwsThrowable{
  33. // Write code here that turns the phrase above into concrete actions
  34. // For automatic transformation, change DataTable to one of
  35. // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
  36. // E,K,V must be a scalar (String, Integer, Date, enum etc)
  37. List<List<String>>list= arg1.raw();
  38. System.out.println(list.get(0));
  39. System.out.println(arg1.toString());
  40. }
  41. @When("^demoinfo ([^\"]*)$")
  42. publicvoid demoinfo_name(String name)throwsThrowable{
  43. // Write code here that turns the phrase above into concrete actions
  44. System.out.println(name+"demoinfo_name");
  45. //Assert.assertTrue(false);
  46. }
  47. @Then("^appdemo ([^\"]*)$")
  48. publicvoid appdemo_info(String name )throwsThrowable{
  49. // Write code here that turns the phrase above into concrete actions
  50. System.out.println(name+"appdemo_info");
  51. }
  52. @When("^call me$")
  53. publicvoid call_me()throwsThrowable{
  54. // Write code here that turns the phrase above into concrete actions
  55. System.out.println("call me");
  56. }
  57. @Then("^docall$")
  58. publicvoid docall()throwsThrowable{
  59. // Write code here that turns the phrase above into concrete actions
  60. System.out.println("docall");
  61. }
  62. @Given("^firstw \"([^\"]*)\"$")
  63. publicvoid firstw(String arg1)throwsThrowable{
  64. // Write code here that turns the phrase above into concrete actions
  65. System.out.println("firstw");
  66. }
  67. @When("^demoinfo$")
  68. publicvoid demoinfo()throwsThrowable{
  69. // Write code here that turns the phrase above into concrete actions
  70. System.out.println("demoinfo");
  71. }
  72. @When("^printinfos$")
  73. publicvoid printinfos(List<String> info)throwsThrowable{
  74. // Write code here that turns the phrase above into concrete actions
  75. // For automatic transformation, change DataTable to one of
  76. // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
  77. // E,K,V must be a scalar (String, Integer, Date, enum etc)
  78. info.forEach(newConsumer<String>(){
  79. @Override
  80. publicvoid accept(String t){
  81. // TODO Auto-generated method stub
  82. System.out.println(t+"demo info");
  83. }
  84. });
  85. }
  86. @Then("^appdemo$")
  87. publicvoid appdemo()throwsThrowable{
  88. // Write code here that turns the phrase above into concrete actions
  89. System.out.println("appdemo");
  90. }
  91. }
  1. <dependencies>
  2. <dependency>
  3. <groupId>info.cukes</groupId>
  4. <artifactId>cucumber-java</artifactId>
  5. <version>1.2.5</version>
  6. <scope>test</scope>
  7. </dependency>
  8. <dependency>
  9. <groupId>info.cukes</groupId>
  10. <artifactId>cucumber-junit</artifactId>
  11. <version>1.2.5</version>
  12. <scope>test</scope>
  13. </dependency>
  14. <dependency>
  15. <groupId>junit</groupId>
  16. <artifactId>junit</artifactId>
  17. <version>4.11</version>
  18. <scope>test</scope>
  19. </dependency>
  20. </dependencies>
  21. <build>
  22. <plugins>
  23. <plugin>
  24. <artifactId>maven-compiler-plugin</artifactId>
  25. <version>3.1</version><!--$NO-MVN-MAN-VER$ -->
  26. <configuration>
  27. <source>1.8</source>
  28. <target>1.8</target>
  29. </configuration>
  30. </plugin>
  31. </plugins>
  32. </build>
  33. <repositories>
  34. <repository>
  35. <id>sonatype-snapshots</id>
  36. <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  37. <snapshots>
  38. <enabled>true</enabled>
  39. </snapshots>
  40. </repository>
  41. </repositories>
 

Cucumber 使用例子

原文:http://www.cnblogs.com/rongfengliang/p/6339408.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!