What Is BDD ?
Behavior-driven development is basically evolved from Test-driven development. It differs by written in different languages and it will improve the communication between tech and non-tech teams and shareholders because the test cases written used this BDD are so much simpler than you think so even the non tech people can easily able to understand it in a first glance. In both development approaches are only based on tests cases but in BDD, tests are more user-focused and also it will work based on the system’s behavior.
Let’s look the actual formula of BDD,
The formula is, ‘Given-When-Then’ BDD which referred as,
Given – scenario
When – action
Then – Output
This formula makes our work lot easier to write BDD test cases for our application.
Cucumber is one of the test framework which supports BDD. In this framework, We are using simple and plain English for writing test cases. This framework basically built in Ruby but also we can able to use it in different technologies.
SpecFlow is developed from the cucumber framework which is built under Ruby. And it is similar like Cucumber because this also proclaims the simple user-friendly approach and this framework mostly used in.Net Projects.
Benefits of using BDD:-
Check out some of the cool benefits of using BDD for writing your test cases,
- Here you can define the ‘behavior’ instead of defining test
- To easy to write test cases & time
- Criteria of the client can be easily achieved.
- Capable of reaching wider audience because even the non-technical persons can cable to understand.
Architecture Of BDD Test Case Flow:
Once your first scenario passes, then it will move to the next one, and the same process will apply for each scenario.
BDD Tools in Rails:-
BDD has the in-built testing libraries which can help us to generate a new application with default options. And all these testing libraries are comes from Ruby. Also there are tools which makes BDD easier to apply. Other side, even in Rails we have many tools to help us to write automated test in some of other popular frameworks such as RSpec, Capybara, Cucumber. For the main testing library, we can use RSpec and Cucumber for writing high-level acceptance test. Now, will see the how to use these gems in rails application.
RSpec is a unit test framework, Tests are written in RSpec based on the ‘behavior’ of an application while being tested. RSpec does not focus on how the application works and but instead on how it behaves.
1. Add gem ‘rspec-rails’ like
group :development, :test do
2. bundle install
3. Run the command rails generate rspec: install it will create a folder of spec
4. Execute the rspec with bundle exec rspec and it will run all the spec files
RSpec.describe Article, :type => :model do
context "with 2 or more articles" do
it "sorts them in reverse order" do
commentOne = article.comments.create!(:body => "comment one")
commentTwo = article.comments.create!(:body => "comment two")
expect(article.reload.comments).to eq([commentTwo, commentOne])
It will read the plain text description of your application, organized in scenarios. Here the code is developed using concrete code, and it will also interact with your application from the user’s standpoint.
1. Add gem ‘cucumber-rails’ in your Gemfile
group: test do
2. bundle install
3. Run the command rails generate cucumber: install it will create a folder of spec
4. bundle exec cucumber and it will run all the spec files
Feature: Hello Cucumber
Scenario: User clicks the link
Given I am on the homepage
When I click the provided link
Then I should see the link click confirmation
For each scenario, we need to provide the corresponding steps definitions in ruby code. Below example will hep you to understand,
Then(/^I should see the link click confirmation$/) do
Was it helpful? Find more blogs on latest technologies, feed your self with more informative blogs on all latest technologies. Also you can avail the best in class and web and mobile app development service from highly skilled developers. For more inquiries reach us via email@example.com
Latest posts by Nagarani Gorantla (see all)
- 10 Common Mistakes That Angular Developers Will Commit - June 21, 2019
- Top 10 Angular CLI Commands To Boost Your Productivity - December 24, 2018
- How To Build Rock Solid Ruby On Rails App With BDD - November 15, 2018