Thursday, January 9, 2014

Cucumber : Advantages and Disadvantages

Cucumber : Advantages and Disadvantages

Cucumber is a testing tool that I have been exposed to since about May 2013. After a solid 7 months of using this on a daily basis I grown to I actually quite like it.

Cucumber is written in a behavior driven development (BDD) and is used with the scripting language Ruby, which is awesome check out my previous blog post.  But you can also use it with different platforms , but I highly suggest ruby.

Moving on.

Let’s talk about the structure of cucumber really quickly.


Here we have a very very basic structure of cucumber. All of these files are required to run your tests. The env.rb is the very first file that is ran when cucumber is executed.  If you have any set up that needs to happen before the initial test is started this is the place to do that. Then you have your feature file and step definitions which are explained further down.


Cucumber is written using the syntax of gherkin. * I see what you did there* Gherkin is a natural language for testing. Natural language, meaning that it’s readable and understandable to those who don’t program.

EX:
Given I go to “www.google.com”
And you search for “Technical Hannah”
When the search is shown
Then I click on Hannahs blog

BOOM. There you go, nothing too difficult. So gherkin is saved in what is called a feature file. These are the files that cucumber looks for when ran. A feature file looks like the following :

@tag
Feature: Teaching Cucumber
                Scenario : Search for Technical Hannah on Google

Given I go to “www.google.com”
And you search for “Technical Hannah”
When the search is shown
Then I click on Hannahs blog

It’s as easy at that. Now you might notice a few new things added here. The “ @tag” the “feature” and the  “scenario”.

Tags are used to call feature files. You can only have one feature per feature file. But you can have many scenarios under one feature.

Not too complicated. You can even put tags over certain scenarios in your feature file if you only want to run that certain scenario.

So if I were to travel to my cucumber file on my computer and run cucumber it would look something like this. (note that when you do this it executes ALL feature files under the feature file folder)

C:\cucumber> cucumber
You can implement step definitions for undefined steps with these snippets:
Given(/^I go to "(.*?)"$/) do |arg1|
  pending # express the regexp above with the code you wish you had
end
And(/^you search for "(.*?)"$/) do |arg1|
  pending # express the regexp above with the code you wish you had
end
When(/^the search is shown$/) do
  pending # express the regexp above with the code you wish you had
end
Then(/^I click on "(.*?)"$/) do |arg1|
  pending # express the regexp above with the code you wish you had
end
 * you add your own ruby scripts here 
Cool , we now have our step definitions that will execute our cucumber file. Notice that when I created the feature file there were quotations around some of the words inside the feature. When the step definitions are created those are seen as variables. This makes it easier to reuse code in your testing system , this is one of my favorite parts about cucumber. If we go back to the feature file we just have to change the variables to anything that we want and the ruby that you've associated with your step definitions should execute correctly.

After you run your tests your test results will show up inside of the command prompt.

Why cucumber is awesome :
1.       Upper level management can read it and it will make sense to them.
2.       Quick and easy set up and execution
3.       Efficient testing

Why Cucumber is not-so-awesome:
1.       I have yet to figure out a way to pass variables between the different lines of gherkin.
2.       Causes the tests to run slower which can be a pain when trying to figure out the execution time of a program.

Overall Cucumber is awesome. It’s a really rad testing tool and I highly suggest you use it if you can. If you need to learn ruby to use it. DO IT!! Ruby is a quick and easy language to learn and it’s fairly powerful when partnered with cucumber.

Happy testing J

6 comments:


  1. After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in



    Selenium training in Chennai

    ReplyDelete
  2. Graton Resort & Casino - Mapyro
    Find your way around 보령 출장마사지 the casino, find a game area and get directions. A number of 수원 출장마사지 different 전라북도 출장안마 casino game shows 대구광역 출장안마 the location of 계룡 출장샵 the casino,

    ReplyDelete