반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

Cucumber Introduction:


Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application. It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.


Cucumber는 BDD (Behavior Driven Development) 프레임 워크를 기반으로 웹 응용 프로그램에 대한 acceptance 테스트를 작성하는 데 사용되는 도구입니다. 비즈니스 분석가, 개발자, 테스터 등이 쉽게 읽을 수 있고 이해할 수있는 형식 (일반 영어와 같은)으로 기능 검증을 자동화 할 수 있습니다.


Cucumber feature files can serve as a good document for all. There are many other tools like JBehave which also support BDD framework. Initially Cucumber was implemented in Ruby and then extended to Java framework. Both the tools support native JUnit.


Cucumber feature 파일은 훌륭한 문서 역할을 할 수 있습니다. BDD 프레임 워크를 지원하는 툴 들 로는 JBehave 등과 같은 다른 많은 도구들도 있습니다. 처음에 Cucumber는 Ruby에서 구현되었고 Java 프레임 워크로 확장되었습니다. 두 도구 모두 native JUnit을 지원합니다.


Behavior Driven Development is extension of Test Driven Development and it is used to test the system rather than testing the particular piece of code. We will discuss more about the BDD and style of writing BDD tests.


Behavior Driven Development는 Test Driven Development의 확장이며 특정 코드를 테스트하는 대신 시스템을 테스트하는 데 사용됩니다. 아래에 BDD 및 BDD 테스트 작성 스타일에 대해 자세히 설명합니다.


Cucumber can be used along with Selenium, Watir, and Capybara etc. Cucumber supports many other languages like Perl, PHP, Python, .Net etc. In this tutorial we will concentrate on Cucumber with Java as a language.


Cucumber는 Selenium, Watir, Capybara 등과 함께 사용할 수 있습니다. Cucumber는 Perl, PHP, Python, .NET 등의 많은 다른 언어를 지원합니다.이 튜토리얼에서는 Java와 함께 Cucumber를 언어로 사용합니다.




Cucumber Basics:


In order to understand cucumber we need to know all the features of cucumber and its usage.


Cucumber를 이해하기 위해서는 Cucumber의 모든 특징과 사용법을 알아야합니다.


#1) Feature Files:


Feature files are essential part of cucumber which is used to write test automation steps or acceptance tests. This can be used as live document. The steps are the application specification. All the feature files ends with .feature extension.


Feature file은 테스트 자동화 단계 또는 acceptance 테스트를 작성하는 데 사용되는 Cucumber의 핵심 부분입니다. 이것은 live document로 사용할 수 있습니다. steps는 application specification입니다. 모든 Feature file은 .feature 확장자로 끝납니다.



Sample feature file:

Feature: Login Functionality Feature

In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working

Scenario: Login Functionality

Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER” and Password “PASSWORD”
Then login should be successful

Scenario: Login Functionality

Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER1” and Password “PASSWORD1”
Then error message should be thrown


#2) Feature:


This gives information about the high level business functionality (Refer to previous example) and the purpose of Application under test. Everybody should be able to understand the intent of feature file by reading the first Feature step. This part is basically kept brief.


여기에는 대략적인 개념의 business functionality (이전 예 참조) 및 테스트중 인 응용 프로그램의 목적에 대한 정보가 있습니다. 첫 번째 Feature step을 읽으면 누구나 이 Feature file의 의도를 이해할 수 있어야 합니다. 이 부분은 기본적으로 간략하게 작성합니다.


#3) Scenario:

Basically a scenario represents a particular functionality which is under test. By seeing the scenario user should be able to understand the intent behind the scenario and what the test is all about. Each scenario should follow given, when and then format. This language is called as “gherkin”.


기본적으로 시나리오는 테스트중인 특정 기능을 나타냅니다. 시나리오 사용자는 시나리오의 의도와 그 테스트가 무엇인지 이해할 수 있어야합니다. 각 시나리오는 주어진 시간과 형식을 따라야합니다. 이 언어는 "작은 Cucumber (gherkin)"라고 불립니다.


  1. Given: As mentioned above, given specifies the pre-conditions. It is basically a known state.
  2. When: This is used when some action is to be performed. As in above example we have seen when the user tries to log in using username and password, it becomes an action.
  3. Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation.
  4. Background: Whenever any step is required to perform in each scenario then those steps needs to be placed in Background. For Instance: If user needs to clear database before each scenario then those steps can be put in background.
  5. And: And is used to combine two or more same type of action.

Example:

Feature: Login Functionality Feature

Scenario: Login Functionality
Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER”
And password as “password”
Then login should be successful
And Home page should be displayed

Example of Background:

Background:

Given user logged in as databases administrator
And all the junk values are cleared


#4) Scenario Outline:

Scenario outlines are used when same test has to be performed with different data set. Let’s take the same example. We have to test login functionality with multiple different set of username and password.

시나리오 개요는 동일한 테스트가 여러 다른 data set로 수행되어야 할 때 사용됩니다. 같은 예를 들어 봅시다. 여러 다른 사용자 이름 및 비밀번호 세트로 로그인 기능을 테스트해야합니다.


Feature: Login Functionality Feature

In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working

Scenario Outline: Login Functionality

Given user navigates to SOFTWARETESTINGHELP.COM
When user logs in using Username as <username> and Password <password>
Then login should be successful

Examples:
|username         |password          |
|Tom                     |password1        |
|Harry                   |password2        |
|Jerry                    |password3        |

Note:

  1. As shown in above example column names are passed as parameter to When statement.
  2. In place of Scenario, you have to use Scenario Outline.
  3. Examples are used to pass different arguments in tabular format. Vertical pipes are used to separate two different columns. Example can contain many different columns.

     
    위의 예에서와 같이 열 이름은 매개 변수로 When 문에 전달됩니다.
    Scenario 대신 Scenario Outline을 사용해야합니다.
    이 예제는 다른 인수를 표 형식으로 전달하는 데 사용됩니다. Vertical pipes는 두 개의 서로 다른 columns을 분리하는 데 사용됩니다. 이 예제에 많은 다른 열을 포함 할  수 있습니다.




#5) Tags:

Cucumber by default runs all scenarios in all the feature files. In real time projects there could be hundreds of feature file which are not required to run at all times.


기본적으로 Cucumber는 모든 Feature file에서 모든 시나리오를 실행합니다. 실시간 프로젝트에는 항상 실행될 필요가 없는 수백 개의 Feature file이있을 수 있습니다.


For instance: Feature files related to smoke test need not run all the time. So if you mention a tag as smokeTest in each feature file which is related to smoke test and run cucumber test with @SmokeTest tag . Cucumber will run only those feature files specific to given tags. Please follow the below example. You can specify multiple tags in one feature file.


예 : smoke test와 관련된 Feature file은 항상 실행될 필요는 없습니다. 따라서 smoke test와 관련된 각 Feature file에서 smokeTest로 태그를 언급하고 @SmokeTest 태그로 Cucumber 테스트를 실행하면됩니다. Cucumber는 특정 태그에 해당하는 Feature file 만 실행합니다. 아래의 예를 따르십시오. 하나의 Feature file에 여러 개의 태그를 지정할 수 있습니다.


Example of use of single tags:


@SmokeTest

Feature: Login Functionality Feature

In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working

Scenario Outline: Login Functionality

Given user navigates to SOFTWARETESTINGHELP.COM
When user logs in using Username as <username> and Password <password>
Then login should be successful

Examples:
|username         |password          |
|Tom     |password1        |
|Harry   |password2        |
|Jerry    |password3        |

Example of use of multiple tags:


As shown in below example same feature file can be used for smoke test scenarios as well as for login test scenario. When you intend to run your script for smoke test then use @SmokeTest. Similarly when you want your script to run for Login test use @LoginTest tag.

아래 예제에서와 같이 로그인 테스트 시나리오는 물론 Smoke Test 시나리오에도 동일한 Feature file을 사용할 수 있습니다. Smoke Test를 위해 스크립트를 실행하려면 @SmokeTest를 사용하십시오. 마찬가지로 로그인 테스트를 위해 스크립트를 실행하려면 @LoginTest 태그를 사용하십시오.


Any number of tags can be mentioned for a feature file as well as for scenario.


Feature file뿐만 아니라 시나리오에 대해서도 임의의 수의 태그를 사용 할 수 있습니다.


@SmokeTest @LoginTest


Feature: Login Functionality Feature

In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working

Scenario Outline: Login Functionality

Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as <username> and Password <password>
Then login should be successful

Examples:
|username         |password          |
|Tom     |password1        |
|Harry   |password2        |
|Jerry    |password3        |


Similarly you can specify tags to run specific scenario in a feature file. Please check below example to run specific scenario.


마찬가지로 태그를 지정하여 Feature file에서 특정 시나리오를 실행할 수 있습니다. 특정 시나리오를 실행하려면 아래 예제를 확인하십시오.


Feature: Login Functionality Feature

In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working

@positiveScenario
Scenario: Login Functionality

Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER” and Password “PASSWORD”
Then login should be successful

@negaviveScenario
Scenario: Login Functionality

Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER1” and Password “PASSWORD1”
Then error message should throw



#6) Junit Runner:


To run the specific feature file cucumber uses standard Junit Runner and specify tags in @Cucumber. Options. Multiple tags can be given by using comma separate. Here you can specify the path of the report and type of report you want to generate.


특정 Feature file을 실행하려면 cucumber가 표준 Junit Runner를 사용하고 @Cucumber에 태그를 지정하십시오. 옵션. 쉼표로 구분하여 여러 태그를 지정할 수 있습니다. 여기에서 생성하려는 보고서의 경로와 유형을 지정할 수 있습니다.


Example of Junit Runner:

1import cucumber.api.junit.Cucumber;</pre>
2import org.junit.runner.RunWith;
3@RunWith(Cucumber.class)
4@Cucumber.Options(format={"SimpleHtmlReport:report/smokeTest.html"},tags={"@smokeTest"})
5Public class JUnitRunner {
6}


Similarly you can give instruction to cucumber to run multiple tags. Below example illustrates how to use multiple tags in cucumber to run different scenarios.


마찬가지로 여러 개의 태그를 실행하기 위해 Cucumber에게 지시를 내릴 수 있습니다. 아래 예제는 Cucumber에서 여러 개의 태그를 사용하여 다른 시나리오를 실행하는 방법을 보여줍니다.


1import cucumber.api.junit.Cucumber;
2 import org.junit.runner.RunWith;
3 @RunWith(Cucumber.class)
4 @Cucumber.Options(format={"SimpleHtmlReport:report/smokeTest.html"},tags={"@smokeTest",”@LoginTest”})
5 Public class JUnitRunner {
6}



#7) Cucumber Report:


Cucumber generates its own html format. However better reporting can be done using Jenkins or bamboo tool. Details of reporting are covered in next topic of cucumber.


Cucumber는 자체적으로 HTML 형식을 생성합니다. Jenkins 또는 bamboo 도구를 사용하여 더 나은 보고를 수행 할 수 있습니다. 보고의 세부 사항은 Cucumber의 다음 주제에서 다룹니다.


Cucumber Project Setup:


Detail explanation of cucumber project set up is available separately in next tutorial. Please refer to Cucumber Tutorial Part2 from more information about project setup. Remember there is no extra software installations required for cucumber.


Cucumber 프로젝트 설정에 대한 자세한 설명은 다음 자습서에서 별도로 설명됩니다. 프로젝트 설정에 대한 자세한 내용은 Cucumber Tutorial Part2를 참조하십시오. Cucumber에 필요한 추가 소프트웨어 설치가 없음을 기억하십시오.


Implementation of Feature file:

We have to implement these steps in Java in order to test the feature files. Need to create a class which contains those given, when and then statements. Cucumber uses its annotations and all the steps are embedded in those annotations (given, when, then).Each phrase starts with “^” so that cucumber understands the start of the step. Similarly each step ends with “$”. User can use regular expressions to pass different test data. Regular expressions take data from feature steps and passes to step definitions. The order of parameters depends how they are passed from feature file. Please refer next tutorial for project setup and mapping between feature files and java classes.


Feature file을 테스트하려면 Java에서 이러한 steps를 구현해야합니다. 주어진, when 및 then 문을 포함하는 클래스를 작성해야합니다. Cucumber는 annotations을 사용하고 모든 step들은 annotations에 포함되어 있습니다 (given, when, then). 각 phrase는 "^"로 시작하여 Cucumber가 단계의 시작을 이해할 수 있도록합니다. 마찬가지로 각 단계는 "$"로 끝납니다. 사용자는 regular expressions을 사용하여 다른 테스트 데이터를 전달할 수 있습니다. 정규식 regular expressions은 feature steps에서 데이터를 가져 와서 step definitions로 전달합니다. 매개 변수 parameters 순서는 feature file에서 전달되는 방법에 따라 다릅니다. 피쳐 파일과 자바 클래스 간의 프로젝트 설정과 매핑에 대해서는 다음 튜토리얼을 참조하십시오.


Example:


Below example is to illustrate how feature files can be implemented.


아래 예제는 Feature file을 구현하는 방법을 보여줍니다.


In this example we have not used any selenium API. This is to just show how cucumber works as standalone framework. Please follow next tutorial for selenium integration with cucumber.


이 예제에서는 selenium API를 사용하지 않았습니다. Cucumber가 독립 프레임 워크로 어떻게 작동하는지 보여주기위한 것입니다. selenium과 Cucumber의 통합에 대한 내용은 next tutorial을 참조하세요.


1public class LoginTest {
2@Given("^user navigates to SOFTWARETETINGHELP.COM$")
3public void navigatePage() {
4system.out.println(“Cucumber executed Given statement”);
5}
6@When("^user logs in using Username as \"(.*)\" and Password \"(.*)\"$")
7public void login(String usename,String password) {
8system.out.println(“Username is:”+ usename);
9system.out.println(“Password is:”+ password);
10}
11@When("^click the Submit button$")
12public void clickTheSubmitButton() {
13system.out.println(“Executing When statement”)
14}
15@Then("^Home page should be displayed$")
16public void validatePage() {
17system.out.println(“Executing Then statement”)
18}
19@Then("^login should be successful$")
20public void validateLoginSuccess() {
21system.out.println(“Executing 2<sup>nd</sup> Then statement”)
22}
23}


When you execute cucumber runner class, cucumber will start reading feature file steps. For example, when you execute @smokeTest, cucumber will read Feature step and Given statement of scenario. As soon as cucumber finds Given statement, same Given statement will be searched in your java files. If same step is found in java file then cucumber executes the function specified for the same step otherwise cucumber will skip the step.


Cucumber runner class를 실행하면 Cucumber가 feature file steps를 읽습니다. 예를 들어 @smokeTest를 실행하면 cucumber는 Feature step과 Given of scenario 문을 읽습니다. Cucumber가 Given 문을 찾자마자 java 파일에서 동일한 Given 문이 검색됩니다. java 파일에서 동일한 단계가 발견되면 cucumber는 동일한 단계에 대해 지정된 함수를 실행하고 그렇지 않은 경우 그 step을 건너 뜁니다.


Conclusion:


In this tutorial, we have covered features of cucumber tool and its usage in real time scenario.
Cucumber is a most favorite tool for many projects as it is easy to understand, readable and contains business functionality.


이 튜토리얼에서는 Cucumber 도구의 기능과 그 사용법을 real time scenario 로 다루었습니다.


Cucumber는 이해하기 쉽고 읽기 쉽고 비즈니스 기능을 포함하고있어 많은 프로젝트에서 가장 많이 사용되는 도구입니다.


In the next chapter we will cover how to setup a cucumber – java project and how to integrate Selenium WebDriver with Cucumber.


다음 장에서는 Cucumber 자바 프로젝트를 설정하는 방법과 Selenium WebDriver를 Cucumber와 통합하는 방법에 대해 설명합니다.


반응형