Unit testing is a method of software testing where individual units of software code are tested to validate whether they are fit for use and if each unit is performing as it should. In most programming languages, the smallest unit that can be isolated is typically a function, subroutine, method, module, or object. Unit testing can save time in the long run by fixing errors on the front end.
Credit: Tutorialspoint.com, “Unit Testing”
Developers conduct unit tests to
- Help fix bugs early in the development cycle
- Understand the testing code base and make changes quickly
- Have a source of project documentation through the unit test for the final deliverable
How to conduct a unit test
To conduct a unit test, a developer will write a section of code to test a specific function in a software application. Unit testing can be done manually or automatically. The manual approach typically requires step-by-step documentation and is no longer commonly used due to the time and effort required.
Using the automated approach, a developer writes a section of code in the application purely to test the function. To ensure the unit test is thorough, the developer will isolate the function to help reveal unnecessary dependencies between the code being tested and other units. When the application is deployed, the test code is removed.
Developers typically use a unit test framework to support test automation and develop automated test cases. From start to finish, a developer creates a test case, reviews and reworks the test, baselines the test by developing automated test cases, and executes the test case.