CSC/ECE 517 Fall 2010/ch1 1f ap
Introduction
Benefits of unit test frameworks
- Test Driven Development
Unit testing frameworks for Ruby
Test::Unit
Rspec
Rspec is one more unit test framework available for ruby programmers and this framework adopts Behaviour Driven development paradigm .In this we write test cases that resembles spoken English, even people with little idea about the test cases can comprehend what the test case is doing.
Some keyword that you need to know before jumping into technical aspects about Rspec.
- Expectations - These are assertion statments used inside the test case.
- Example - This is a test method and collection of expectations(assertion statements).
- Example Group - Collection of examples is called Example group and also called test case.
Lets take an example and explain on how to write a unit test case using Rspec framework.
describe "Checking Account" do it "should have a balance greater than 0" do CheckingAccount = Account.new CheckingAccount account.balance.should > Money.new(0, :USD) end it “...” do //some expectations end end
Lets go through elements of this test case aka code example group.
- it () :: This is called code example and it is similar to test method in Test::unit .This method takes string as an argument and the string describes the functionality/ behaviour we are going to test about the system . it() method has a code block , which is collection of expectations also called assertions.Expectations are enclosed between the do ... end keywords.