CSC/ECE 517 Fall 2011/ch2 2e kt: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 6: Line 6:


=== Test::Unit KH ===  
=== Test::Unit KH ===  
=== MiniTest::Unit TG ===
=== Mini::Test TG ===
 
Evolution of Mini::Test
 
Although Ruby’s Test::Unit has been used for years and is a favorite, (mostly due to its inclusion with the Ruby standard library) many Ruby developers felt the need for a more modern test infrastructure.  This caused them to abandon Test::Unit and pull in additional test gems (e.g. rspec, shoulda, cucumber, etc.).  With the new standard Mini::Test, however, this may be a thing of the past.
 
 
 
Mini::Test was created to be small, clean and fast.  Test::Unit could be rather slow and contained some little-used features, such as test cases, GUI runners and some assertions.  Mini::Test provides 90% of Test::Unit that people were using as well as some additional features.
 
 
 
Most of the assertions in Mini::Test are the same as those in its predecessor.  The major difference is in the negative assertions.  In Test::Unit where you have a assert_not_''something'', in Mini::Test you would use refute_something.  (assert_not_raise and assert_not_throws are not available.)
 
 
 
Mini::Test provides the following assertions:
 
{| class="wikitable" border="1" padding="2"
 
|-
| assert|| assert_block || refute
|-
| assert_empty|| assert_equal || refute_empty || refute_equal
|}
 
=== RSpec KH ===
=== RSpec KH ===
=== Shoulda TG ===
=== Shoulda TG ===

Revision as of 00:58, 18 September 2011

Overview

TDD vs BDD

Ruby Testing Frameworks

Test::Unit KH

Mini::Test TG

Evolution of Mini::Test

Although Ruby’s Test::Unit has been used for years and is a favorite, (mostly due to its inclusion with the Ruby standard library) many Ruby developers felt the need for a more modern test infrastructure. This caused them to abandon Test::Unit and pull in additional test gems (e.g. rspec, shoulda, cucumber, etc.). With the new standard Mini::Test, however, this may be a thing of the past.


Mini::Test was created to be small, clean and fast. Test::Unit could be rather slow and contained some little-used features, such as test cases, GUI runners and some assertions. Mini::Test provides 90% of Test::Unit that people were using as well as some additional features.


Most of the assertions in Mini::Test are the same as those in its predecessor. The major difference is in the negative assertions. In Test::Unit where you have a assert_not_something, in Mini::Test you would use refute_something. (assert_not_raise and assert_not_throws are not available.)


Mini::Test provides the following assertions:

assert assert_block refute
assert_empty assert_equal refute_empty refute_equal

RSpec KH

Shoulda TG

Cucumber TG

Criteria

  • IDE integration
  • Test output detail
  • Testing constructs available
  • TDD or BDD
  • Documentation
  • Learning curve and ease of use


Framework Matrix

Framework Website Documentation IDE Integration Type Ease of Use
Unit::Test
MiniTest::Unit

Demo Code

 class Account
   @balance
   @name
 
   attr_accessor :balance
   attr_accessor :name
 
   def initialize(amount)
     @balance = amount
   end
 
   def deposit(amount)
     @balance += amount
   end
 
   def addinterest(rate)
     @balance *= (1 + rate)
   end
 
   def withdrawal(amount)
     @balance -= amount
   end
 end


Test::Unit

 require "test/unit"
 require_relative("../Account.rb")
 
 class AccountTest < Test::Unit::TestCase
 
   def test_balance
     a = Account.new(100)
     assert_equal(100, a.balance())
   end
 
   def test_deposit 
     a = Account.new(100)
     assert_equal(200, a.deposit(100))
   end
   
   def test_withdrawal
     a = Account.new(100)
     assert_equal(50, a.withdrawal(50))
   end
   
   def test_name
     a = Account.new(100)
     a.name = "Checking"
     assert_not_nil(a.name())
   end
 
   def test_interest
     a = Account.new(100)
     assert_equal(a.addinterest(0.5), 150)
   end
 
   def test_fail
     a = Account.new(100)
     assert_equal(a.balance(), 200)
   end
 end

References

[1] http://ruby-toolbox.com/categories/testing_frameworks.html