首页 > 其他分享 >Gherkin scenario vs scenario outline

Gherkin scenario vs scenario outline

时间:2023-02-17 18:24:00浏览次数:37  
标签:inputs scenario Scenario into vs entered Gherkin outline

scenario vs scenario outline

In Gherkin, the scenario is a simple test case that describes a particular behavior of the system under test. A scenario outline, on the other hand, is a template for a set of scenarios that share a common structure and steps, but differ in the specific values used in the steps.

In a scenario, you typically describe a specific set of inputs and expected outputs for a particular feature or function. In contrast, a scenario outline is used when you need to test the same behavior for multiple sets of inputs, for example, testing a login feature with different usernames and passwords.

A scenario outline consists of a template that defines placeholders for the specific values to be used in the steps, and a table that provides the values to be used in each scenario that is generated from the outline. The scenarios generated from a scenario outline are also referred to as "scenario instances".

Scenario outlines can help reduce repetition in your feature files and make it easier to maintain them, as you can modify the template and table to generate new scenarios quickly. However, they can also lead to more complex feature files and make it harder to read and understand the tests, so it's important to use them judiciously.

 

talk is cheap, show me the code for above scenario vs scenario outline

Sure! Here's an example of a scenario and a scenario outline written in the Gherkin language:

Scenario: Login with valid credentials
  Given I am on the login page
  When I enter "username" and "password"
  And I click the login button
  Then I should be redirected to the home page

Scenario Outline: Login with invalid credentials
  Given I am on the login page
  When I enter "<username>" and "<password>"
  And I click the login button
  Then I should see an error message

  Examples:
    | username | password  |
    | user1    | password1|
    | user2    | password2|
    | user3    | password3|

 

In the above example, the first scenario is a simple scenario that tests the login functionality with valid credentials. The second scenario is a scenario outline that tests the login functionality with invalid credentials. The scenario outline is repeated for each set of example data provided in the Examples table.

 

So the scenario outline is something like TestCase in NUnit?

Yes, that's a good way to think about it. Just like how NUnit allows you to run the same test with different inputs by using the [TestCase] attribute, Scenario Outline in Gherkin allows you to write a single scenario with placeholders that can be filled in with different inputs when the scenario is run. This can be a useful way to avoid duplicating test code when you have a number of similar scenarios to run, but with different inputs.

 

And from the above code for  scenario vs scenario outline, the keypoint in outline is that it uses <parameter name> as place holder? Could you give me another example to show the differences between them? such as a math calculation for plus

Sure, let's take a simple example of adding two numbers, where we want to test multiple combinations of numbers using Scenario Outline and Scenario.

Here is an example using a Scenario Outline:

Scenario Outline: Add two numbers
  Given I have entered <num1> into the calculator
  And I have entered <num2> into the calculator
  When I press add
  Then the result should be <result> on the screen

  Examples:
  | num1 | num2 | result |
  | 2    | 3    | 5      |
  | 4    | 5    | 9      |
  | 6    | 7    | 13     |

 

 And here is an example using a Scenario:

Scenario: Add two numbers
  Given I have entered 2 into the calculator
  And I have entered 3 into the calculator
  When I press add
  Then the result should be 5 on the screen

Scenario: Add two other numbers
  Given I have entered 4 into the calculator
  And I have entered 5 into the calculator
  When I press add
  Then the result should be 9 on the screen

Scenario: Add two more numbers
  Given I have entered 6 into the calculator
  And I have entered 7 into the calculator
  When I press add
  Then the result should be 13 on the screen

 As you can see, the difference between the two is that the Scenario Outline allows you to specify a template that can be filled in with various inputs, whereas the Scenario is more specific and only tests one combination of inputs at a time. The Scenario Outline is more flexible and can be useful when you want to test multiple combinations of inputs, whereas the Scenario is more straightforward and easier to read when you only have a few inputs to test.

 

 

标签:inputs,scenario,Scenario,into,vs,entered,Gherkin,outline
From: https://www.cnblogs.com/chucklu/p/17131180.html

相关文章

  • VS Code常用插件
    C/C++ExtensionPack:C/C++扩展包GitLensGitHistoryGitGraphDoxygenDocumentationGenerator:注释工具BetterComments:代码注释高亮BetterC++Syntax:C/C++语......
  • VSCode Markdown preview enhanced 配置中文字体, 自定义css的方法
    在Ctrl+Shift+P命令菜单中选择CustomizeCSS这是我基于SolarizedLight的配置文件注意,只需要在系统中(我的是Win10)安装思源宋体CNMedium,在系统的字体当中找到它......
  • vs2017出现了E1696、E0282、E0260等错误
    具体解决步骤如下: 打开VisualStudioInstaller,点击修改,点击单个组件,在编译器、生成工具和运行时中找到Windows通用CRTSDK,勾选安装打开项目文件,点击工具栏中的调试,打......
  • VSTO - 残留历史记录的问题
    对于插入后,残留历史记录主要是因为Open时Untitled参数设置为msoFalse使得操作的不是临时文件,所以会产生记录!//第二个参数Untitledvarsource=Globals.Th......
  • lvs+keepalive 工作原理及搭建
    目录lvs+keepalive工作原理及搭建nginx应用场景keepalive介绍keepalived工作原理VRRP工作原理简述keepalive软件结构开始搭建环境准备工作:安装Nginx什么是高可用?解决的问......
  • VS CODE 基本的CC++环境配置
    VSCODE基本的C/C++环境配置​ 以前用vscode来左编译器的时候,是直接创建3个json文件,然后粘贴上网上教程中的代码,要改一些比如g++\gdb的路径(安装mingw64的时候带的文件)......
  • windows中使用git,vscode提交代码
    一.使用Gitbash操作1.准备条件与初始化新建一个文件夹dm-configcddm-config#初始化gitinit#全局配置添加邮箱和用户名gitconfig--globaluser.name"jack"......
  • VScode、PHP运行
    下载vscode,并安装PHP插件打开小皮面板创建一个新的网站输入域名,选择根目录并点击确定创建成功浏览器输入http://myblog验证在vscode打开新建的myblog文件夹新建一个index.p......
  • 创建myblog程序、VScode中编辑程序,运行
    先打开vscode,点击扩展,在搜索框中搜索php,下载前三个(也可以只下载一个)然后打开小皮面板,点击网站,创建网站,输入域名和改根目录(如果你能找到根目录的话,可改可不改),点击确认,就......
  • 在小皮面板中创建myblog程序、VScode中编辑程序,运行
    1.打开小皮面板创建网站基本配置如下记住根目录   在vscode内搜索php并安装 打开网站根目录的文件夹,并新建文件index.php 输入代码 输入http://myb......