CSC/ECE 517 Fall 2010/ch1 1f vn: Difference between revisions
Line 12: | Line 12: | ||
Test fixture represents the initial environment setup(eg. initialization data) and the expected outcome of the tests for that environment. This is typically done in the setup()/teardown() methods and it helps to separate test initialization/cleanup from the actual tests. It also helps to reuse the same fixture for more than one tests. | Test fixture represents the initial environment setup(eg. initialization data) and the expected outcome of the tests for that environment. This is typically done in the setup()/teardown() methods and it helps to separate test initialization/cleanup from the actual tests. It also helps to reuse the same fixture for more than one tests. | ||
=== | ===Assertions=== | ||
The core part of test::unit framework is the ability to assert statements using a set of assert methods. | The core part of test::unit framework is the ability to assert statements using a set of assert methods. An assertion is the statement of expected outcome, if it is true the test will pass, otherwise the test will fail. For the full list of assertion methods provided by test::unit refer to [http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html test::unit assertions] | ||
===Example=== | ===Example=== |
Revision as of 20:40, 6 September 2010
Introduction
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. Unit testing frameworks provides us with constructs and methodologies which simplifies the process of unit testing. This chapter walks through three different unit testing frameworks available for Ruby, explains how to use them with examples, and compares them with one another. The three commonly used unit testing frameworks for ruby are
- Test::Unit
- Shoulda
- RSpec
Test::Unit
Ruby comes with an in-built, ready to use unit testing framework called Test::Unit. It is a XUnit type framework and typically have a setup method for initialization, a teardown method for cleanup and the actual test methods itself. The tests themselves are bundled separately from the code it is testing. The test methods should start with 'test' prefix. This helps in isolating the test methods from the helper methods.
Test Fixture
Test fixture represents the initial environment setup(eg. initialization data) and the expected outcome of the tests for that environment. This is typically done in the setup()/teardown() methods and it helps to separate test initialization/cleanup from the actual tests. It also helps to reuse the same fixture for more than one tests.
Assertions
The core part of test::unit framework is the ability to assert statements using a set of assert methods. An assertion is the statement of expected outcome, if it is true the test will pass, otherwise the test will fail. For the full list of assertion methods provided by test::unit refer to test::unit assertions