CSC/ECE 517 Fall 2011/ch2 2e gp: Difference between revisions
No edit summary |
|||
Line 19: | Line 19: | ||
[http://en.wikipedia.org/wiki/Unit_testing Unit Testing] is a method by which we can isolate and test a unit functionality of the program, typically individual methods during and long after the code is written. | [http://en.wikipedia.org/wiki/Unit_testing Unit Testing] is a method by which we can isolate and test a unit functionality of the program, typically individual methods during and long after the code is written. | ||
== Cucumber == | == Cucumber == | ||
Cucumber is a testing tool that follows the BDD approach of testing. Cucumber written itself in Ruby programming language allows the execution of feature documentation written in natural language often termed as [[http://en.wikipedia.org/wiki/User_story]] user stories | |||
== Test::Unit == | == Test::Unit == | ||
The in-built, ready to use unit testing mechanism for Ruby is called [http://www.ensta-paristech.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html Test::Unit].It belongs to the XUnit family unit testing framework. It has a setup method for initialization, a teardown method for cleanup and the actual test methods itself. The tests are bundled separately in a test class in the code it is aimed to test. | The in-built, ready to use unit testing mechanism for Ruby is called [http://www.ensta-paristech.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html Test::Unit].It belongs to the XUnit family unit testing framework. It has a setup method for initialization, a teardown method for cleanup and the actual test methods itself. The tests are bundled separately in a test class in the code it is aimed to test. |
Revision as of 17:07, 17 September 2011
Testing Frameworks for Ruby
This page serves as a knowledge source for understanding the different Testing Frameworks available for Ruby.
Introduction
No code is perfect from the word go! Testing plays an important role in System Development Life Cycle. During testing, we follow a taxonomic procedure to uncover defects at various stages. A test framework provides various Test Types, Test Phases, Test Models, Test Metrics and acts as a guideline as to how to perform effective testing <ref> http://www.scribd.com/doc/15909730/Software-Testing-Framework </ref>. Various testing tools are available for Rubylanguage, each having some unique features over others. Here is a brief introduction and feature comparisons of popular testing frameworks.
Testing Approaches
Before we delve into testing for Ruby, in general, these are the followed approaches in industry today
Test Driven Development
This strategy, (abbreviated as TDD) <ref> http://en.wikipedia.org/wiki/Test-driven_development </ref>, though cumbersome due to its methodology develops efficient code. First a unit test is written for a function, even before the code for that function is developed. Based on this test minimal code is developed to ensure the test succeeds; if not the code is modified until test run successfully. In this iterative approach, effort is made to ensure flawless code is developed.
Behavior Driven Development
BDD <ref> http://en.wikipedia.org/wiki/Behavior_Driven_Development </ref> as its popularly know, upholds the traditional iterative workflow of Test Driven Development, but it focuses on defining behaviors that is easy to understand to naive people (with no programming background) by writing tests in natural language. This approach focuses more on looking at code development from a behavioral abstraction. For example testing the code for a recipe belonging to a category of a cookbook, in BDD would be something like 'A recipe can't be without a category'
Unit Testing
Unit Testing is a method by which we can isolate and test a unit functionality of the program, typically individual methods during and long after the code is written.
Cucumber
Cucumber is a testing tool that follows the BDD approach of testing. Cucumber written itself in Ruby programming language allows the execution of feature documentation written in natural language often termed as [[1]] user stories
Test::Unit
The in-built, ready to use unit testing mechanism for Ruby is called Test::Unit.It belongs to the XUnit family unit testing framework. It has a setup method for initialization, a teardown method for cleanup and the actual test methods itself. The tests are bundled separately in a test class in the code it is aimed to test.
Features
This salient features of the Test::Unit Framework are:-
Assertions
We can use Test::Unit to make assertions. The test is successful if the assertion is true and fails if the assertion is false. All the assertion methods provided by test::unit can be found at Test::Unit::Assertions.
assert( boolean, [message] ) | True if boolean |
assert_equal( expected, actual, [message] ) assert_not_equal( expected, actual, [message] ) |
True if expected == actual |
assert_raise( Exception,... ) {block} assert_nothing_raised( Exception,...) {block} |
True if the block raises (or doesn't) one of the listed exceptions. |
Test-Fixtures
Using a test fixture, we can initialize (and cleanup) the common set of data for two or more tests hence eliminating unnecessary duplication. Fixtures are written in the setup() and teardown() methods.
Example
Shoulda
RSpec
References
<references/>