수색…
소개
작은 오이 (Gherkin)는 테스트 자동화 및 테스트 문서 작성을위한 비즈니스 언어입니다. 그것은 오이에 의해 이해되고 함께 행동 주도 개발 도구로 존재합니다.
통사론
- 기능 :이 키워드는 테스트 또는 문서화되는 기능의 기본 설명 또는 이름입니다.
- 배경 :이 키워드는 기능의 모든 시나리오보다 먼저 실행될 단계를 나타냅니다.
- 시나리오 :이 키워드는 기능을 테스트하는 특정 시나리오의 이름 또는 기본 설명을 나타냅니다.
- 시나리오 개요 :이 키워드는 대괄호로 묶인 열 이름으로 명시 적으로 전달 된 예제에 나열된 모든 인수에 대해 시나리오가 N 번 실행됨을 나타냅니다.
- 예 :이 키워드는 시나리오 개요로 전달되는 정적 인수 목록을 나타냅니다.
- 주어진 :이 키워드는 주어진 단계 또는 계속하기 전에 가정되는 전제 조건을 나타냅니다. Arrange, Act, Assert 패러다임에서 주어진 "Arrange"를 나타냅니다.
- When : when이 키워드는 when 단계 또는 어설트 될 행동을 나타냅니다. Arrange, Act, Assert 패러다임에서는 주어진 "Act"를 나타냅니다.
- 그런 다음 :이 키워드는 다음 단계, 즉 행동의 결과가 확인되는 단계를 나타냅니다. Arrange, Act, Assert 패러다임은 주어진 "Assert"를 나타냅니다.
- 그리고 :이 키워드는 위의 키워드 중 하나와 함께 사용됩니다. 주어진 문장이 두 개인 경우, Given을 명시 적으로 두 번 호출하는 대신 "주어진 A와 B"라고 말할 수 있습니다.
기본 사항
이 예제는 작은 오이의 오이 피처 파일의 기본 구조를 살펴볼 것입니다. 지형지 물 파일은 기본 구문에서 여러 키워드를 사용합니다.
기본 키워드를 살펴 보겠습니다.
- 기능 : 이 키워드는 테스트 또는 문서화되는 기능의 기본 설명 또는 이름입니다.
- 시나리오 : 이 키워드는 기능을 테스트하는 특정 시나리오의 이름 또는 기본 설명을 나타냅니다.
- 이 키워드가 주어지면 주어진 단계 또는 계속하기 전에 가정되는 전제 조건을 나타냅니다. Arrange, Act, Assert 패러다임에서 주어진 "Arrange"를 나타냅니다.
- 이 키워드는 경우 단계, 또는에 대해 주장 할 수있는 동작을 표현합니다. Arrange, Act, Assert 패러다임에서는 주어진 "Act"를 나타냅니다.
- 그런 다음 이 키워드는 다음 단계, 즉 행동의 결과가 확인되는 단계를 나타냅니다. Arrange, Act, Assert 패러다임은 주어진 "Assert"를 나타냅니다.
- 그리고이 키워드는 위의 키워드 중 하나와 함께 사용됩니다. 주어진 문장이 두 개인 경우, Given을 명시 적으로 두 번 호출하는 대신 "주어진 A와 B"라고 말할 수 있습니다.
- 그러나이 키워드는 Given , When and Then 와 함께 사용되어 발생하지 않아야 함을 나타냅니다. 그렇다면 B.는 아니지만.
모든 키워드는 새 행에 있어야하며 Gherkin 파서가 인식 할 수 있도록 새 행의 첫 단어 여야합니다. Feature 및 Scenario 키워드는 아래 예제와 같이 콜론이 있어야합니다. 감안할 때, 언제, 그리고, 그리고 콜론이 필요하지 않습니다.
키워드 외에도 설명 및 주석을 쓸 수 있습니다. 설명은 키워드 다음에 있지만 같은 줄에 있으며 키워드 아래의 줄에 주석이 표시됩니다. 지형지 물 코멘트를 작성할 때, 행동의 다른 결과로 이어지는 모서리와 조건을 개괄적으로 설명하는 규칙을 제공하는 것이 일반적입니다.
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Scenario: The user successfully logs in with valid credentials
This scenario tests that a user is able to successfully login
provided they enter a valid username, valid password, and
currently have an active subscription on their account.
Given the user is on the login page
When the user signs in with valid credentials
Then the user should be logged in
매개 변수가있는 단계
Gherkin을 작성할 때 테스트 계획을 구현하는 엔지니어가 재사용을위한 단계를 매개 변수화하려는 경우가있을 수 있습니다. 단계는 정규 표현식 캡처 그룹을 통해 매개 변수를받습니다. ( 엔지니어링 참고 사항 : 정규식에서 각 캡처 그룹에 대해 일치하는 매개 변수가없는 경우 "CucumberException : Arity mismatch"가 throw 될 수 있습니다.) 아래 예제에서 인수를 큰 따옴표로 묶기로 결정했습니다 as는 정수를 인수로 사용합니다.
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Scenario: The user successfully logs in with valid credentials
This scenario tests that a user is able to successfully login
provided they enter a valid username, valid password, and
currently have an active subscription on their account.
Given the user is on the login page
When the user signs in with "valid" credentials
Then the user should be logged in
Scenario: The user attempts to log in with invalid credentials
This scenario tests that a user is not able to log in when
they enter invalid credentials
Given the user is on the login page
When the user signs in with "invalid" credentials
Then the user should be logged in
Scenario: The user is locked out after too many failed attempts
This scenario validates that the user is locked out
of their account after failing three consecutive
attempts to log in
Given the user is on the login page
When the user fails to log in 3 times
Then the user should be locked out of their account
기능 배경
위 예제에서 알 수 있듯이 동일한 단계를 여러 번 다시 작성합니다.
Given the user is on the login page
이것은 특히 지루할 수 있습니다. 특히 재사용되는 단계가 두 개 이상있는 경우 더욱 그렇습니다. 작은 오이는 우리에게 다음과 같이 작업 할 수있는 또 다른 키워드를 제공함으로써이 문제에 대한 해결책을 제공합니다 : 배경 : .
background 키워드는 지형지 물의 모든 시나리오보다 먼저 선언 된 단계를 실행합니다. 모든 시나리오에서 필요하다고 긍정적 인 경우가 아니면 배경 단계를 추가하지 마십시오. 다른 키워드와 마찬가지로 배경에는 설명 또는 이름이 있으며 그 아래에 설명이있을 수 있습니다. 피쳐와 시나리오와 마찬가지로 콜론 (:)으로 배경을 진행해야합니다.
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Background: The user starts out on the login page
Given the user is on the login page
Scenario: The user successfully logs in with valid credentials
This scenario tests that a user is able to successfully login
provided they enter a valid username, valid password, and
currently have an active subscription on their account.
When the user signs in with "valid" credentials
Then the user should be logged in
Scenario: The user attempts to log in with invalid credentials
This scenario tests that a user is not able to log in when
they enter invalid credentials
When the user signs in with "invalid" credentials
Then the user should be logged in
Scenario: The user is locked out after too many failed attempts
This scenario validates that the user is locked out
of their account after failing three consecutive
attempts to log in
When the user fails to log in 3 times
Then the user should be locked out of their account
시나리오 개요
경우에 따라 인수를 대체하여 동일한 시나리오를 반복하여 다시 반복 할 수 있습니다. 이 경우 Gherkin은 이러한 상황을 수용 할 수있는 몇 가지 새로운 키워드를 제공합니다. 시나리오 개요 및 예 : . 시나리오 개요 키워드는 Cucumber에게 시나리오가 목록에서 인수를 대체하여 여러 번 실행될 것이라고 알려줍니다. 예제 키워드는 목록이 명시 적으로 표기되기 전에 호출됩니다. 시나리오 개요에 대한 인수는 각괄호로 묶어야합니다. 아래 예제에서 각괄호 안에 감싸는 인수 이름은 예제에 나열된 열 이름에 해당합니다. 각 열은 첫 행에 열 이름이있는 세로 막대로 구분됩니다.
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Background: The user starts out on the login page
Given the user is on the login page
Scenario Outline: The user successfully logs in with their account
This scenario outlines tests in which various users attempt
to sign in successfully
When the user enters their <username>
And the user enters their <password>
Then the user should be successfully logged on
Examples:
| username | password |
| frank | 1234 |
| jack | 4321 |
태그
문서화를 위해 범주별로 테스트 계획 또는 시나리오를 필터링 할 수 있습니다. 개발자는 동일한 범주를 기반으로 테스트를 실행할 수 있습니다. Gherkin에서는 태그 사용자를 통해 기능 및 개별 시나리오를 분류 할 수 있습니다. 아래 예에서 Feature 키워드가 태그 "@Automation"인 것을 확인하십시오. Gherkin은 이것을 "@"기호의 사용자가 태그로 인식합니다. 이 예에서 엔지니어는 모든 테스트가 자동화 가능한 것은 아니지만 일부 테스트는 수동 QA로 수행해야하는 자동화에 이러한 테스트가 사용된다는 것을 분명히하고 싶어합니다.
또한 @Production 태그가 시나리오 테스트 사용자에게 추가되었음을 알립니다. 이 예제는이 시나리오가 응용 프로그램의 프로덕션 환경에서만 활성화되기 때문입니다. 개발자는 개발 중에 샌드 박스 계정을 잠그지 않으려합니다. 이 태그를 사용하면이 테스트는 프로덕션 환경에서만 실행될 수 있습니다.
마지막으로 시나리오 개요에는 @Staging이라는 태그가 있습니다. 이 예제에서 사용되는 계정은 준비 계정이며 다른 환경에서는 작동하지 않기 때문입니다. @Production 태그와 마찬가지로이 옵션은 Staging 환경에서만 실행됩니다.
이는 태그를 사용할 수있는 위치, 방법 및 이유에 대한 몇 가지 예일뿐입니다. 궁극적으로 이러한 태그는 개발자와 개발자에게 의미가있을 것이며, 무엇이든 될 수 있으며 적합하다고 생각 되더라도 분류하는 데 사용할 수 있습니다.
@Automation
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Background: The user starts out on the login page
Given the user is on the login page
Scenario: The user successfully logs in with valid credentials
This scenario tests that a user is able to successfully login
provided they enter a valid username, valid password, and
currently have an active subscription on their account.
When the user signs in with "valid" credentials
Then the user should be logged in
Scenario: The user attempts to log in with invalid credentials
This scenario tests that a user is not able to log in when
they enter invalid credentials
When the user signs in with "invalid" credentials
Then the user should be logged in
@Production
Scenario: The user is locked out after too many failed attempts
This scenario validates that the user is locked out
of their account after failing three consecutive
attempts to log in
When the fails to log in 3 times
Then the user should be locked out of their account
@Staging
Scenario Outline: The user successfully logs in with their account
This scenario outlines tests in which various users attempt
to sign in successfully
When the user enters their <username>
And the user enters their <password>
Then the user should be successfully logged on
Examples:
| username | password |
| frank | 1234 |
| jack | 4321 |
작은 오이 팁
- 각 시나리오는 하나의 행동을 테스트합니다.
- 시나리오는 선언적 방식으로 작성됩니다.
- 시나리오 내부에 부수적 인 세부 사항 피하기
- 명백한 것은 생략하십시오.
- 결계 단계를 피하십시오
- 시나리오를 짧게 유지하십시오.
- 동일한 기능에서 많은 시나리오를 수행 할 필요가 없습니다.
- 설명적인 시나리오 이름 사용
- 하나만 가지고 계십시오.
- 다음 단계에서 "해야 함"을 사용하십시오.