Cucumber


Cucumber is a testing framework which supports Behaviour Driven Development (BDD) 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 was implemented in Ruby and then extended to Java framework. It supports to jUnit. Behavior Driven Development is extension of Test Driven Development.

Cucumber Basic:

1-Feature files

2-Feature

3- Sceanarios

4-jUnit runner

1-Feature files:Feature files are the important part of cucumber which is used to write the automation script.These files can be used as a documents.Feature file saves as a .feature extension.

test.feature

Feature: about Scala developer
In order to get a high paid job
As a Scala developer
I want to learn Scala development

Scenario: I am a Scala developer.
Given I am a Scala developer
When I apply for a job
Then I got  less  paid job
And I am  not satisfied for this salary
But My parents is  still  satisfied

2-Feature: This part gives the information of high level of business requirement.Description of feature is very short.

3-Scenario: Scenario defined the particular functionality which is under test.In scenarios we used different annotation.

@Given

@When

@Then

@And

@But

 

4-JunitRunner:For running the feature file cucumber used Junit runner.

For running the cucumber you have to add cucumber jar files in your project.

Here is the code:

test.feature

Feature: about Scala developer
In order to get a high paid job
As a Scala developer
I want to learn Scala development

Scenario: I am a java developer.
Given I am a “java” developer
When I apply for a job
Then I got  less  paid job
And I am  not satisfied for this salary
But My parents is  still  satisfied

Scenario: I am a “Scala” developer.
Given I am a “Scala” developer
When I apply for a job
Then I got “high” paid job
And I am “highly” satisfied for this salary
But My parents is “highly” satisfied

now we make a java file.

tester.java

package cucumberstart;

import cucumber.api.java.en.And;
import cucumber.api.java.en.But;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class Tester {

@Given("^I am a \"([^\"]*)\" developer$")
public void I_am_a_java_developer(String devType)
{
System.out.println("....................................");
System.out.println("@Given........I am a "+devType+" developer");

}

@When("^I apply for a job$")
public void I_apply_for_a_job()
{
System.out.println("@When........I apply for a job");
}

@Then("^I got \"([^\"]*)\" paid job$")
public void I_got_less_paid_job(String lessType)
{
System.out.println("@Then........I_got_"+lessType+"_paid_job");
}

@And("^I am \"([^\"]*)\" satisfied for this salary$")
public void I_am_not_satisfied_for_this_salary(String satisfiedType)
{

System.out.println("@And........I am "+satisfiedType+" satisfied for this salary");
}

@But("^My parents is \"([^\"]*)\" satisfied$")
public void My_parents_is_still_satisfied(String parentType)
{
System.out.println("@But........My parents is "+parentType+" satisfied");
}

}

We can easily see the html report created by cucumber.

cucumberscreenshot

Advertisements
This entry was posted in Scala and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s