Thursday 29 August 2013

TDD and BDD

Why is Behaviour Driven Development better than Test Driven Development? Why should I switch to BDD?”

Well BDD focuses on specifying what will happen next. where as TDD focuses on setting up a set of conditions and then looking at the output. 

BDD

Behaviour driven development comes from TDD and focuses more on the expected/desired behaviour of your application and using this to drive your design and development process. Generally BDD focuses on obtaining a clear understanding of desired software behaviour through discussion with stakeholders. It extends TDD by writing test cases in a natural language that non-programmers can read. Behaviour-driven developers use their native language in combination with the ubiquitous language of domain driven design to describe the purpose and benefit of their code. This allows the developers to focus on why the code should be created, rather than the technical details, and minimizes translation between the technical language in which the code is written and the domain language spoken by the business, users, stakeholders, project management, etc.
BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.

TDD

Test Driven Development is all about writing tests first. This basically forces you to write your own client before you write your application code. The cycle is generally write a test for an API that doesn’t exist, run the test expecting it to fail, go write your API code, run your test again and make sure it passes. Then write your next test… and so on.
Once the test passes, observe the resulting design and refractor to remove any duplication you see. It is natural at this point to judge the design as too simple to handle all of the responsibilities this code will have.

If person adhere more strongly to TDD principles he spend less time reworking later. The amount of time spent is all in how well you write unit tests though. If the unit tests don’t capture the expected behaviour, all the time spent on them is wasted.

Differences between BDD and TDD

1) BDD focuses on specifying what will happen next. where as TDD focuses on setting up a set of conditions and then looking at the output.

2) BDD specifies behaviours while TDD specifies outcomes.

3) BDD can be layered, while outcomes(TDD) cannot.

4) TDD is for testing and we can't perform Design process, Requirements capturing and Behaviour specification in TDD, but these can be possible in BDD.

5) BDD is mainly used as a communication tool. its main goal is to write executable specifications which can be understood by the domain experts.

The main difference between BDD and TDD is wording. as these are important for communicating your intend.

Getting Started with Ruby 2 and Rails 4


If you are new to Rails then you will might want to check out my other post basic installation packages as the following steps will assume a similar setup.

Installing Ruby 2
  • Ruby 2 is the latest stable version to start working with it.
  • rvm install ruby-2.0.0
  • rvm list
  • rvm use ruby-2.0.0-p247
Installing Rails 4

Before installing a new version of Rails, I like to switch to a new RVM gemset. If you're not using RVM, don't worry about this step. 
A Best Rails 4 Book to start with
$ rvm use @rails4 --create
Installing Rails 4 is as easy as it ever way, just use gem install.
            gem install rails -v=4.0.0.rc2
Rails 4 is now the latest stable release so it's much easier to get going with it. 
Once the gem installer has done it's thing you can now check the Rails version withrails -v and start a new project in the usual way.








How to create a Rails 3 project with Rails 4 installed
With Rails 4 now taking priority over Rails 3 in your gem list how do you make a new Rails 3.2 project without going through the hassle of uninstalling Rails 4.
Simple really, check the versions of Rails you have installed already with gem list rails.
*** LOCAL GEMS ***
rails (4.0.0, 3.2.13)
The output shows I have the Rails 4.0.0 and 3.2.13 installed and you can simply append that version number to your rails command like so.
rails _3.2.13_ new myproject
This will create a project in the usual way but this time using the 3.2.13 version of the gem.
Don't forget that you should use bundle exec within your project when callingrails generate and friends so that the correct gem version according to the projects Gemfile is used. For example: bundle exec rails generate model User.