Cucumber 使用例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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\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>

  

posted on   荣锋亮  阅读(1203)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2016-01-22 RabbitMQ 集群与高可用配置
2014-01-22 node express 返回json object
2014-01-22 CodeIgniter 安装指导

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示