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