如何在 Cucumber 中使用正则表达式?
在 Cucumber 中,我们可以使用正则表达式来选择功能文件中的集合类似语句。
示例
功能文件
Feature: Exam Syllabus Scenario Outline: Summer and Winter Exam Schedule Given Exam time table in summer season Given Mathematics and Physics Syllabus Given Exam time table in winter season
步骤定义文件中包含 @Given("^Exam time table in ([^\"]*) season$"),通过正则表达式的帮助将功能文件中的两个 Given 语句映射在一起。
示例
@Given ("^Exam time table in ([^\"]*) season$")
public void timeTable(String season){
if (season.equals("winter")){
System.out.println("The winter syllabus");
}else{
System.out.println("The summer syllabus");
}
}
@Given ("^Mathematics and Physics Syllabus$")
public void syllabusList(){
System.out.println("Mathematics and Physics syllabus is");
}
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP