CSC/ECE 517 Fall 2010/ch1 1f ap: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 36: Line 36:
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  
1. ''' 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.
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.


<u>'''General structure of it() method:.'''</u>
will paste the code later over here , need some formatting.
'''Arguments to it ''' :: it( ) method takes a single String, an optional Hash and an optional block
2. '''describe() ::'''  We use describe() method to define example group aka  test case in Test::Unit.        This acts as an abstraction to many code examples -i,e its a wrapper around  multiple it() functions .
'''General structure of describe() construct looks like this.'''
need to paste code over here and it requires formatting
'''Arguments''':Arguments passed to describe function are string and they describe the subset of behaviour exhibited by the object.
3. '''Methods'''





Revision as of 11:04, 7 September 2010

Introduction


Benefits of unit test frameworks

  1. 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.

1. 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.

General structure of it() method:.

will paste the code later over here , need some formatting.

Arguments to it  :: it( ) method takes a single String, an optional Hash and an optional block

2. describe() :: We use describe() method to define example group aka test case in Test::Unit. This acts as an abstraction to many code examples -i,e its a wrapper around multiple it() functions .

General structure of describe() construct looks like this.

need to paste code over here and it requires formatting

Arguments:Arguments passed to describe function are string and they describe the subset of behaviour exhibited by the object.

3. Methods


shoulda


Comparison of unit test frameworks


References and conclusion