Unit Testing is the process of testing small, individual components of a software application. Testing a function or a class by itself falls under unit testing. Unit testing involves writing code to test code as there is no user interface to manually test these individual components. Typically, unit testing is a task performed by developers, but coders in the testing team could easily add variations to the unit tests to improve test coverage.
Why Unit Test?
Unit Testing helps to verify the correctness of individual components. It helps to isolate components and pin-point issues. Finding issues by unit testing is easier and quicker than identifying issues in the application, with all components working together. Also, automated unit tests help a great deal during regression. Imagine testing all features of the application after a minor change, modification or bug fix, it would be a nightmare!
How do you Unit Test?
Unit Tests should be written before programming and coded along with the new functionality. So a new or modified code block is accompanied by its unit test case. Write unit tests for code that is exposed, so public methods, documented parts of an API, etc should have unit tests. Write your unit tests to a standard and common interface like jUnit, nUnit, etc. even if it is only a handful of tests. Don't create test cases with their own main methods! Very soon your project code base will grow and the number of unit tests will also go up and running the unit tests will require significant time and effort. Pick a standard test harness to run your tests, don't write your own! Such proven and widely used test infrastructure also comes with neat features to report test results. Unit tests should not require major environment setup. If you are testing parts of an enterprise application, use mock objects in your tests. Don't write application specific unit tests. Write unit tests to test the correctness of modules. Testing how the modules behave together in the application can be done later in Integration Tests or Functional Tests.
Unit Testing has become more important and relevant in newer development methodologies like Test Driven Development, eXtreme Programming, etc. The benefit of this approach (as opposed to practices where you write functional code and then think about testing) is that you can take smaller, quicker steps to reach your goal. Unit testing your code helps to find issues at step one and the turn around time to fix the problems is also very short. Refactoring is easier as you have a suite of tests to confirm that you did not break anything. While Unit Testing still needs to be complimented with Integration and Functional Testing, it is a good start to a successful project.
Published by Subu Iyer
- Tips on Testing a TransistorArticle describing the method and reasoning behind testing a semiconductor using an ohm meter.
- Testing DHCP Settings for Avaya IP TelephonesSeveral methods of obtaining DHCP information and testing DHCP for deployment of Avaya VoIP phones.
- EDI Testing GuidelinesGenerally three types of testing are there. Viz. Unit testing, Independent unit testing, Acceptance testing. Unit, Independent Unit & Acceptance Testing is done by Developer, Assigned Tester & Client respectively.
- Scalability Testing and Avoiding Problems at the Eleventh HourVery large scale software systems are a breed apart: scalability is vital to their success. If you leave performance testing to the end, you risk finding your systems will fail to scale and you're left with staggerin...
- Seattle Biomedical Research Institute's Decision to Give Patients Malaria and Our...Years ago, before Minoxidil and Rogaine became approved for use, my husband was a test subject for the drugs. He had to be pulled from the tests and recovered his health. Are the newest test subjects fully aware of th...
- Facts About Automated Testing
- Software Tester Skills: Testing, Domain Knowledge and Technical Expertise
- Software Quality Assurance Agile Testing Types and Processes
- Successful Software Testing Automation
- Testing Database Applications
- Power Tips for Software Testers
- Should Standardized Tests Be Required for All Public, Private, and Home Schools?
