CSC/ECE 517 Fall 2010/ch1 1f ap: Difference between revisions
(→Rspec) |
No edit summary |
||
Line 32: | Line 32: | ||
<span style="color:#ff0000">'''end''' </span> | <span style="color:#ff0000">'''end''' </span> | ||
<span style="color:#ff0000">'''end''' </span> | <span style="color:#ff0000">'''end''' </span> | ||
Lets go through elements of this test case aka code example group. | 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. | |||
# ''' 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. | |||
===shoulda=== | ===shoulda=== |
Revision as of 04:34, 7 September 2010
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.