Wednesday, July 17, 2013

Hello Cucumber: An Introduction to Behavior Driven Development BDD with Cucumber

Background: I am no Cucumber expert, but had to learn it really insanely fast for a startup work, and understand the concepts. I thought I will give an overview, in case you land in my shoes and don't know where to begin.

  • Cucumber is a tool for Behavior Driven Development, commonly known as BDD
  • Cucumber has been popularly used in Rails as a testing Gem
  • It uses Rspec to run Test Driven Development, commonly known as TDD
  • Rspec is a popular Rails testing tool
  • You can run Cucumber and Rspec in command line, when developing a Rails app
  • Cucumber focuses on the features for example
    • Given I am on the homepage
    • And I am a login user
    • When I click on the signout button
    • Then I should be signed out successfully
  • Rspec is used more as a unit test, lower level more focused on the components like Controller / Model and the methods of controllers and models than features
    • it may test that the bank_sum method successfully display bank account total
    • or the controller will lead us to the right URL
  • But it's very important to use Rspec with Cucumber
  • Cucumber's features are linked to tests as well, with a little bit of regex, which stands for Regular Expression, so it will be really good to know it soon!
    • <#TODO Dilys to post an example here soon>
  • In Rails Cucumber can be used in conjunction with Factory Girl and Faker (which help you build dummy data sets called fixtures) to be feed into the controllers and models, methods that you have created. Guard,  another gem is also used sometimes. Michael Hartl's famous Rails tutorials covers Guard a bit. One of its functionality| is to do real time testing as the developer is changing the codes.

This should save you quite some reading time to know how Cucumber fits in the world! Hopefully it helps when you frantically start your career as a junior developer. 

Good ways to learn Cucumber as a beginner:
  • read the pre-written codes in your company's project if any exists. They will be in the features folder. The Cucumber gem has to be installed. Note: most testing files should exist in spec
  • read the books I am recommending below, depends on how much time you have
  • search the internet for examples, and watch demos, and actually note down the examples. Take notes, may be with Evernote:
    • Test for button clicking feature
    • Cucumber: Given.... And... When... Then... And...
    • Follow button method
    • Rspec : should have_link(....)
  • Otherwise, it will be tough to remember hybrid English and code syntax of both Rspec and Cucumber.
If you haven't gotten to know Rspec, I recommend you starting with this, and kill two builds with one stone! In fact it will teach you Behavior Driven Development and Test Driven Development too! Highly recommend!

Then you can start with recipes and examples. Examples are easy fast ways to learn. Especially as a developer

Or you can always start with the actual Cucumber book

No comments:

Post a Comment

React UI, UI UX, Reactstrap React Bootstrap

React UI MATERIAL  Install yarn add @material-ui/icons Reactstrap FORMS. Controlled Forms. Uncontrolled Forms.  Columns, grid