Unit and integration testing
Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual function or procedure. Unit tests are created by programmers or occasionally by white box testers.
Ideally, each test case is independent from the others: substitutes like method stubs, mock objects, fakes and test harnesses can be used to assist testing a module in isolation. Unit tests are typically written and run by software developers to ensure that code meets its design and behaves as intended. Its implementation can vary from being very manual (pencil and paper) to being formalized as part of build automation.
Benefits – The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. A unit test provides a strict, written contract that the piece of code must satisfy. As a result, it affords several benefits. Unit tests find problems early in the development cycle. Various benefits of unit testing are
- Facilitates change – Unit testing allows the programmer to refactor code easily at later date.
- Simplifies integration – It reduces uncertainty in the units themselves and can be used in a bottom-up testing style approach.
- Documentation – It is a sort of living documentation of the system.
- Design – The design document (the unit-test itself) can be used to verify that the implementation adheres to the design.
Usage – The goal of a single unit test is to test only some variation of the “unit under test”. If web site developer writes a unit test that aims to verify the result of a particular codepath through a function, web site developer need only be concerned about testing the code that lives in the function body itself. If the function accepts a parameter that represents a complex application “domain object” (such as a resource, a database connection, or an SMTP server), the argument provided to this function during a unit test need not be and likely should not be a “real” implementation object.
Integration testing (sometimes called Integration and Testing, abbreviated “I&T”) is the phase in software testing in which individual software modules are combined and tested as a group. It occurs after unit testing. It takes as its input modules that have been unit tested, groups them in larger aggregates, applies tests defined in an integration test plan to those aggregates, and delivers as its output the integrated system ready for system testing.
It explicitly tests the interaction between two or more “units”. Integration tests verify that the components of web application or web site, work together. Hence, to might make sure that an email was actually sent in an integration test. It has different approaches for testing, which are
- Bottom Up Testing is an approach to integrated testing where the lowest level components are tested first, then used to facilitate the testing of higher level components. The process is repeated until the component at the top of the hierarchy is tested.
- Top Down Testing is an approach to integrated testing where the top integrated modules are tested and the branch of the module is tested step by step until the end of the related module.
- Big Bang – The way this integration testing type works is, most or all of the modules are integrated together to form nearly a complete system. This is very similar to system testing as this basically has a whole system before starting the testing.
Benefits – Various benefits accrued by integration testing are
- Getting I/O functions in early can ease test writing.
- Early demonstration of main functionality can be helpful in highlighting requirements issues
- Observation of test results is reasonably easy.
- Separately debugged modules.
- Easily integrating previously debugged modules