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\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>
Cucumber 使用例子的更多相关文章
- (转载)中文Appium API 文档
该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...
- 中文Appium API 文档
该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...
- Cucumber语法及测试用例<一>
工作原因,最近一直在研究cucumber的 语法以及它和java之间的关系.鉴于是初学者且代码基础薄弱,我开始摸索前行,感谢分享博客且也在一路前行的人儿们. 1.基本语法为:此处举例两种区别一看即知- ...
- Cucumber命令行接口
1. cucumber的命令行选项 首先查看命令行选项.和其它命令行工具一样,cucumber提供了—help选项.下面是cucumber帮助的一个缩减版本: $ cucumber --help -r ...
- uiautomator+cucumber实现自动化测试
前提 由于公司业务要求,所以自动化测试要达到以下几点: 跨应用的测试 测试用例可读性强 测试报告可读性强 对失败的用例有截图保存并在报告中体现 基于以上几点,在对自动化测试框架选型的时候就选择了uia ...
- Cucumber 行为驱动开发简介
Cucumber 是一个能够理解用普通语言 描述的测试用例的支持行为驱动开发(BDD)的自动化测试工具,用Ruby编写,支持Java和.Net等多种开发语言. 现在看看Cucumber中用到的术语 . ...
- 行为驱动:Cucumber + Selenium + Java(四) - 实现测试用例的参数化
在上一篇中,我们介绍了Selenium + Cucumber + Java框架下的使用Tags对测试用例分组的实现方法,这一篇我们用数据表格来实现测试用例参数化. 4.1 什么是用例参数化 实际测试中 ...
- 【Cucumber】【命令行】
知识点 参考:https://www.cnblogs.com/worklog/p/5253297.html cucumber的命令行选项 首先查看命令行选项.和其它命令行工具一样,cucumber提供 ...
- cucumber java从入门到精通(4)Scenario Outline及数据驱动
cucumber java从入门到精通(4)Scenario Outline及数据驱动 到目前为止,我们的TodoList类工作良好,不过离我们的预期--任务清单系统还是有不少差距,究其原因不过如下: ...
随机推荐
- Java中如何获取多维数组的长度
在程序处理中遍历数组是一种很常见的操作,但遍历数组时,我们需要知道数组各维度的长度(一维数组除外,for each 可以遍历),下面举例说明如何求多维数组的长度. 一维 : int [] array ...
- STL学习笔记(转,还是比较全的)
STL简介 1 概况 2 1.1 STL是什么 2 1.2 为什么我们需要学习STL 2 1.3 初识STL 2 1.4 STL 的组成 5 2 容器 6 2.1 基本容器——向量(vector) 6 ...
- python:打包成exe程序
1.需要安装 py2exe 2.示例代码: #exetest.py #创建一个gui界面,只用一个标签和按钮,无功能 from Tkinter import * win = Tk() label = ...
- 严重:Error configuring application listener of class org.springframework.web.util.IntrospectorCleanupListener
mave项目换了一个新的工作空间时出现的问题 原因: 其实是你的jar文件没有同步发布到自己项目的lib目录中(如果你是用Maven进行构建的话) 可以试试 下面的办法 解决方案: 项目点击右键 点击 ...
- 【LeetCode 28_字符串_匹配】Implement strStr()
解法一:Brute-force int strStr(string haystack, string needle) { int m = haystack.size(); int n = needle ...
- Flask_script扩展调用的方式
Flask中flask-script扩展的使用 通过使用Flask-Script扩展,我们可以在Flask服务器启动的时候,通过命令行的方式传入参数.而不仅仅通过app.run()方法中传参 Flas ...
- Shell 命令行求两个文件每行对比的相同内容
Shell 命令行求两个文件每行对比的相同内容 遇到的一个实际问题是,2017年08月01日起,所有未经实名的域名,全部停止解析.而我手上有不少域名,其中很多都是没有实名的.但我不知道哪些实名了,哪些 ...
- PHPStorm 添加支持 PSR-4 命名空间前缀设置
许久没有更新博客啦, 太忙了, 七月这最后一天来写点自己在使用 PHPStorm 上的小却很有用的功能吧. PHPStorm 默认是使用 PSR-0 命名空间规范的, 前提是你需要标记好项目中的源码根 ...
- 深度学习(七十)darknet 实现编写mobilenet源码
一.添加一个新的网络层 (1)parse.c文件中函数string_to_layer_type,添加网络层类型解析: if (strcmp(type, "[depthwise_convolu ...
- matlab下利用K-Means进行图像分类
FIRST & BEST SOLUTION clear all; clc; I_rgb=imread('dog.jpg'); figure();imshow(I_rgb);title('原始图 ...