Testing OverviewIn Waterfall development process, developers finish code then do some ad-hoc testing. In the contrary with Agile development process, testing is part of every Agile iteration and developers are the responsible for testing own code. Also, testing tools & processes are highly automated.
With Behavior-Driven Design (BDD), one has to develop user stories to describe features, then thanks to Cucumber, user stories become acceptance tests and integration tests.
With Test-driven development (TDD), specify step definitions for new story (this may require new code to be written), write unit & functional tests for that code first, before the code itself. In a nutshell, write tests for the code you wish you had.
How both works together? Use Cucumber to describe behavior via features & scenarios (behavior driven design), and RSpec to test individual modules that contribute to those behaviors (test driven development).
When Cucomber test fails, it calls for RSpec test, if it fails you need to add missing methods. Keep iterating until passing feature implementation test, when features are implemented properly it will pass the Cucomber test then keep going to development.
TDD Getting StartedUnit Test should be FIRST: Fast to run, Independent the order of running tests should no matter, Repeatable if a test fails once then it should fail again if we re-run it again (i.e. always same result), Self-checking which means no human intervention to interpret test result as failed or successful. Timely can be run on background while developing and bring developers attention when it find bugs, also when code change test should also.
RSpec is a Domain-Specific Language for testing. DSL stands for small programming language that simpifies one task at expense of generality (e.g. migrations, regexes, SQL). RSpec tests are called specs, and inhabit spec directory.
Typing following command rails generate rspec:install will creates this directory structure:
- app/models/*.rb spec/models/*_spec.rb
- app/controllers/*_controller.rb spec/controllers/*_controller_spec.rb
- app/views/*/*.html.haml (use Cucumber!)
Te be continued from slide 13 ...