BDD自动化测试框架cucumber(1): 最基本的demo
BDD(Behavior Driven Development),行为驱动开发, 对应自动化测试框架,python有behave,java有cucumber, 这次记录cucumber+springboot+maven的自动化测试框架。
基本结构如下:
1)POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent> <groupId>org.example</groupId>
<artifactId>cucumberExample</artifactId>
<version>1.0-SNAPSHOT</version> <!--can set the same version for the same module-->
<properties>
<cucumber.version>2.3.1</cucumber.version>
<cucumber-reporting.version>3.14.0</cucumber-reporting.version>
<maven.compiler.version>3.7.0</maven.compiler.version>
<java.compiler.version>1.8</java.compiler.version>
</properties> <dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${cucumber.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-spring -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>${cucumber-reporting.version}</version>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.compiler.version}</source>
<target>${java.compiler.version}</target>
</configuration>
</plugin>
<plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<inherited>true</inherited>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven.surefire/surefire-junit4 -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
<configuration>
<argLine>-Xmx1024m</argLine>
<argLine>-Xms1024m</argLine>
<forkCount>3.0c</forkCount>
<reuseForks>true</reuseForks>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/demoRunner.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build> </project>
2)features: 最重要的环节,用户场景
@login
Feature: login function Scenario Outline: password checking
Given I have open the login page
And input account=<account>
And input password=<password>
When I click the LOGIN button
Then it return login success to me Examples:
|account|password|
|user1 |password1|
|user2 |password2|
3)steps: 实现feature 里面每一个步骤的逻辑,一句话对应一个step一个方法
备注:这里我还没有加上方法体,以后再加
package steps;
/*
* @author Helen Lee
* @create 2020/9/11
* @description
*/
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Assert; public class login_steps {
@Given("I have open the login page")
public void iHaveOpenTheLoginPage() {
} @Given("input account=(.*)")
public void inputAccountAccount(String account) { } @Given("input password=(.*)")
public void inputPasswordPassword(String password) { } @When("I click the LOGIN button")
public void iClickTheLOGINButton() { } @Then("it return login success to me")
public void itReturnLoginSuccessToMe() {
}
}
4)runner: 执行testcases
/*
* @author Helen Lee
* @create 2020/9/11
* @description
*/ import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; @RunWith(Cucumber.class)
@SpringBootTest
@CucumberOptions(
tags = {"@login"},
features = {"src/main/resources/features"},
glue = {"steps"},
plugin = {
"pretty",
"html:target/cucumber",
"json:target/cucumberReportJsonFiles/cucumber-report.json"
}
)
public class demoRunner {
public void test() {
}
}
完成这四个之后,就可以run demoRunner了,结果如下:跑了user1/password1 和user2/passwords两个test cases
BDD自动化测试框架cucumber(1): 最基本的demo的更多相关文章
- Python BDD自动化测试框架初探
1. 什么是BDD BDD全称Behavior Driven Development,译作"行为驱动开发",是基于TDD (Test Driven Development 测试驱动 ...
- 自动化测试框架Cucumber和Robot Framework的实战对比
自动化测试框架Cucumber和RobotFramework的实战对比 一.摘要 自动化测试可以快速自动完成大量测试用例,节约巨大的人工测试成本:同时它需要拥有专业开发技能的人才能完成开发,且需要大量 ...
- 自动化测试框架Cucumber和RobotFramework的实战对比
转自: http://www.infoq.com/cn/articles/cucumber-robotframework-comparison 一.摘要 自动化测试可以快速自动完成大量测试用例,节 ...
- 接口自动化测试框架Karate入门
介绍 在这篇文章中,我们将介绍一下开源的Web-API自动化测试框架--Karate Karate是基于另一个BDD测试框架Cucumber来建立的,并且共用了一些相同的思想.其中之一就是使用Gher ...
- 移动APP自动化测试框架
简介 移动APP的UI自动化测试长久以来一直是一个难点,难点在于UI的”变”, 变化导致自动化用例的大量维护.从分层测试的角度,自动化测试应该逐层进行.最大量实现自动化测试的应该是单元测试,最容易实现 ...
- 移动APP自动化测试框架对比
转自微信公众号:腾讯移动品质中心TMQ 移动APP的UI自动化测试长久以来一直是一个难点,难点在于UI的”变”, 变化导致自动化用例的大量维护.从分层测试的角度,自动化测试应该逐层进行.最大量实现自动 ...
- 基于Ruby的Watir-WebDriver自动化测试框架
基于Ruby的watir-webdriver自动化测试方案与实施(五) 基于Ruby的watir-webdriver自动化测试方案与实施(四) 基于Ruby的watir-webdriver自动 ...
- IntelliJ IDEA 自动化工具安装并添加自动化测试框架
IntelliJ IDEA是一个用于开发人员开发和测试人员自动化测试的测试工具,类似于eclipse. 优点:插件多自身可以携带,自身携带cucumber自动化测试框架,类似于junit一样 缺点:r ...
- 自动化测试框架的Step By Step搭建及测试实战(1)
1.1什么是自动化测试框架 1.什么是自动化框架 自动化框架是应用与自动化测试的程序框架,它提供了可重用的自动化测试模块,提供最基础的自动化测试功能,或提供自动化测试执行和管理功能的架构模块.它是由一 ...
随机推荐
- 华为开发者大会主题演讲:3D建模服务让内容高效生产
内容来源:华为开发者大会2021 HMS Core 6 Graphics技术论坛,主题演讲<3D建模服务使能3D内容高效生产>. 演讲嘉宾:华为消费者云服务 AI算法专家 3D建模服务(3 ...
- Windows11 如何让开始菜单出现休眠选项(Windows11如何开启休眠功能?)Windows家庭版
1. Windows11新版的菜单找不到调休眠的选项了,所以我们可以用win+r键调出运行,输入control,回车调出「控制面板」 配图: 2. 我的电脑系统是家庭版的Windows11,其它版本这 ...
- 『学了就忘』Linux软件包管理 — 48、给源码包打补丁
目录 1.补丁的生成 2.补丁的打入 在以前的软件源码包,需要打补丁的时候比较多.现在的源码包很少进行打补丁了,因为根据需求安装不同的版本即可,比较商业化了.(也就是知道如何给源码包打补丁就可以了,了 ...
- RocketMQ源码详解 | Broker篇 · 其四:事务消息、批量消息、延迟消息
概述 在上文中,我们讨论了消费者对于消息拉取的实现,对于 RocketMQ 这个黑盒的心脏部分,我们顺着消息的发送流程已经将其剖析了大半部分.本章我们不妨乘胜追击,接着讨论各种不同的消息的原理与实现. ...
- 【Microsoft Azure 的1024种玩法】五、基于Azure Cloud Shell 一站式创建Linux VM
[文章简介] Azure Cloud Shell 是一个用于管理 Azure 资源的.可通过浏览器访问的交互式经验证 shell. 它使用户能够灵活选择最适合自己工作方式的 shell 体验,无论是 ...
- [loj6734]图上的游戏
考虑原图是一条链的情况-- 思路:随机一个点$x$,将其所在段(边集)再划分为两段,重复此过程即可得到该链 实现上,(从左到右)维护每一段的左端点和边集,二分找到最后一个删除后$x$到根不连通的段,那 ...
- [loj2506]tree
2018年论文题,以下是论文前3章主要内容,与原题解相关部分为第4章中的启发式合并,也可快速跳至原题解 1.复杂度分析 Treap 定理1:$n$个节点的Treap的期望深度为$o(\log n)$ ...
- [hdu5245]Joyful
很难考虑矩形覆盖的问题,但可以考虑每一个点被覆盖的概率/期望(把矩形分成九部分后容斥即可),sigma起来即答案 1 #include<bits/stdc++.h> 2 using nam ...
- [atAGC045E]Fragile Balls
构造一张有向图$G=([1,n],\{(a_{i},b_{i})\})$(可以有重边和自环),定义其连通块为将其看作无向图(即边无向)后分为若干个连通块 记$in_{i}$为$i$的入度(即最终盒子中 ...
- 下一代的 3D Tiles 前瞻
下一代的 3D Tiles 前瞻 原文:Introducing 3D Tiles Next, Streaming Geospatial to the Metaverse 原文发布时间:2021年11月 ...