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的更多相关文章

  1. Python BDD自动化测试框架初探

    1. 什么是BDD BDD全称Behavior Driven Development,译作"行为驱动开发",是基于TDD (Test Driven Development 测试驱动 ...

  2. 自动化测试框架Cucumber和Robot Framework的实战对比

    自动化测试框架Cucumber和RobotFramework的实战对比 一.摘要 自动化测试可以快速自动完成大量测试用例,节约巨大的人工测试成本:同时它需要拥有专业开发技能的人才能完成开发,且需要大量 ...

  3. 自动化测试框架Cucumber和RobotFramework的实战对比

    转自: http://www.infoq.com/cn/articles/cucumber-robotframework-comparison   一.摘要 自动化测试可以快速自动完成大量测试用例,节 ...

  4. 接口自动化测试框架Karate入门

    介绍 在这篇文章中,我们将介绍一下开源的Web-API自动化测试框架--Karate Karate是基于另一个BDD测试框架Cucumber来建立的,并且共用了一些相同的思想.其中之一就是使用Gher ...

  5. 移动APP自动化测试框架

    简介 移动APP的UI自动化测试长久以来一直是一个难点,难点在于UI的”变”, 变化导致自动化用例的大量维护.从分层测试的角度,自动化测试应该逐层进行.最大量实现自动化测试的应该是单元测试,最容易实现 ...

  6. 移动APP自动化测试框架对比

    转自微信公众号:腾讯移动品质中心TMQ 移动APP的UI自动化测试长久以来一直是一个难点,难点在于UI的”变”, 变化导致自动化用例的大量维护.从分层测试的角度,自动化测试应该逐层进行.最大量实现自动 ...

  7. 基于Ruby的Watir-WebDriver自动化测试框架

    基于Ruby的watir-webdriver自动化测试方案与实施(五)   基于Ruby的watir-webdriver自动化测试方案与实施(四)   基于Ruby的watir-webdriver自动 ...

  8. IntelliJ IDEA 自动化工具安装并添加自动化测试框架

    IntelliJ IDEA是一个用于开发人员开发和测试人员自动化测试的测试工具,类似于eclipse. 优点:插件多自身可以携带,自身携带cucumber自动化测试框架,类似于junit一样 缺点:r ...

  9. 自动化测试框架的Step By Step搭建及测试实战(1)

    1.1什么是自动化测试框架 1.什么是自动化框架 自动化框架是应用与自动化测试的程序框架,它提供了可重用的自动化测试模块,提供最基础的自动化测试功能,或提供自动化测试执行和管理功能的架构模块.它是由一 ...

随机推荐

  1. 容器安全产品Aqua调研

    前言 近年来,随着云计算的发展,企业数字化的进程不断加快,业务纷纷开始上云,云原生的概念最近两年也是十分火热,在新业务场景下也随之产生了新的安全问题,如k8s安全.devsecops.微服务安全.Se ...

  2. [noi37]列队

    直接统计答案,令dp[i][j]表示前i个数最长的颜色各不相同后缀长度为j的方案数,如果一直令j<m,那么就相当于统计了方案数. 如何推出dp[i][j]呢?考虑i-1的最长前缀是多少:当小于j ...

  3. 解决springboot启动日志异常问题

    问题描述:springboot启动异常,启动后没有日志打印. 问题原因:slf4j日志实现重复,找不到对应实现类. 问题应对: 1. 是不是项目没起来---->打印的日志数据,到这里就不打印了, ...

  4. Qt Creator 源码学习笔记03,大型项目如何管理工程

    阅读本文大概需要 6 分钟 一个项目随着功能开发越来越多,项目必然越来越大,工程管理成本也越来越高,后期维护成本更高.如何更好的组织管理工程,是非常重要的 今天我们来学习下 Qt Creator 是如 ...

  5. Linux设置默认的声卡

    首先查看自己电脑上的声卡 使用命令行查看 orangepi@orangepi3:~$ ll /proc/asound/ total 0 dr-xr-xr-x 4 root root 0 Dec 23 ...

  6. CF1156F Card Bag

    题目传送门. 题意简述:有 \(n\) 张卡牌,每张卡牌有数字 \(a_1,a_2,\cdots,a_n\).现在随机抽取卡牌,不放回,设本次抽到的卡牌为 \(x\),上次抽到的卡牌为 \(y\),若 ...

  7. 以VuePress的v1.x为基础开发-用户手册

    首先配置.vuepress中的config.js module.exports = { title:"用户手册", description: '用户手册', evergreen: ...

  8. 前端4 — jQuery — 更新完毕

    1.下载jQuery 网址:Download jQuery | jQuery  最好下载最新版的,因为有什么bug问题,最新版的都会有,所以学技术就用最新版的,实际开发用的时候就要讲究了 2.开始用j ...

  9. SpringCloud微服务实战——搭建企业级开发框架(三十):整合EasyExcel实现数据表格导入导出功能

      批量上传数据导入.数据统计分析导出,已经基本是系统必不可缺的一项功能,这里从性能和易用性方面考虑,集成EasyExcel.EasyExcel是一个基于Java的简单.省内存的读写Excel的开源项 ...

  10. MapReduce02 序列化

    目录 MapReduce 序列化 概述 自定义序列化 常用数据序列化类型 int与IntWritable转化 Text与String 序列化读写方法 自定义bean对象实现序列化接口(Writable ...