unit testing is a method by which individual units of source code,
sets of one or more computer program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine if they are fit for use.Unit tests are created by programmers or occasionally by white box testers during the development process.The goal of unit testing is to isolate each part of the program and show that the individual parts are correct
Benefits
Find problems early
Unit tests find problems early in the development cycle.Unit tests are created before the code itself
is written. When the tests pass, that code is considered complete.
Facilitates change
Unit testing allows the programmer to re factor code at a later date, and make sure the module still works correctly.Readily available unit tests make it easy for the programmer to check whether a piece of code is still working properly.
Simplifies integration
Unit testing may reduce uncertainty in the units themselves and can be used in a bottom up testing style approach. By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier.
Documentation
Unit testing provides a sort of
living documentation of the system.Unit tests provides a basic
understanding of what functionality is provided by a unit and how to
use it.
Design
Each unit test can be seen as a design element specifying classes, methods, and observable behaviour. The following example is the Testing toRoman against fromRoman
.
class SanityCheck(unittest.TestCase): def testSanity(self): """fromRoman(toRoman(n))==n for all n""" for integer in range(1, 4000): numeral = roman.toRoman(integer) result = roman.fromRoman(numeral) self.assertEqual(integer, result)
This example is a test class that checks the correctness of program that converts the integer given to roman numeral and viceversa. Here the test class checks whether the given integer falls in the
range (0,3999)
Parameterized Unit Testing (PUT)
In Parameterized Unit Tests (PUTs) , that take parameters.PUTs have been supported by JUnit 4 and various .NET test frameworks.
Unit testing limitations
Testing cannot be expected to catch every error in the program. It is
impossible to evaluate every execution path in most trivial
programs.
It will not catch system errors or broader system level errors
Writing the unit tests is the difficulty of setting up realistic and useful tests.Challenge of setting relevant initial condition so that the part of the code being tested behaves as the part of the whole system
Use of a version control system is essential for unit testing.
Applications
Extreme Programming
Unit testing is the cornerstone of extreme programming, which relies on an automated unit testing framework.This automated unit testing framework can be either third party, e.g., xUNIT, or created within the development group.
Techniques
Unit testing is commonly automated but may still be performed manually.unit testing frame work
Unit testing frameworks are most often third-party products that are not distributed as part of the compiler suite. They help simplify the process of unit testing, having been developed for a wide variety of languages.Language-level unit testing support
Languages that directly support unit testing include:
- C
- Java
- Obix
- D
No comments:
Post a Comment