Test Driven Development and Testing Challenges
- June 23, 2016
Test driven development (TDD) is also called test driven design. TDD is a method of software development in which source code is tested over and over again (unit testing).
TDD is more about “Now” which is “to build software that is working for now and can be modified later according to the needs”. Testing is then performed and code is refactored after each testing cycle. This process of refactoring is repeated again and again until all parts of the product are working according to the desired specification. TDD approach is the part of Extreme Programming (XP).
Test driven development is used to build software typically in less time than by using the other and older ways. Both, testers and developers anticipate and are aware that how the software would work in real world. TDD makes sure that all units are at least tested for optimal functionality. Software is being tested from earlier stages so time and cost of debugging is reduced at later stages.
One limitation of TDD is tester can sometimes apply tests incorrectly. And this may result in software units malfunction in real world. User may encounter scenarios which are not implemented by the developer, nor tested by the tester.
Test Driven Development Cycle
1. Adding a Test
The very beginning of a feature is writing a test which can define the functionality or improvements in functionality and which should be very clear and expressive. Programmer fully understands the specifications of features and requirements so he can complete this through use cases and/or user stories to cover the scope.
2. New Test Results
Tests are written for expected fail and success cases. This ensures that new tests don’t get passed without requiring new code changes. New tests should get failed because no new code is written for those tests to pass. So a developer gets more confidence to see his tests getting failed or passed against expected conditions.
Developer writes some code for a test to pass. But this code can always be improved in desired way later. Developer must not code the functionality that is not to be tested in current test run.
4. Test Runs
Tests are conducted at this stage. If they get passed, everyone is sure that newly written code meets the requirements and no old functionality was harmed. New code can always be adjusted if tests don’t work.
5. Code Refactoring
Programmers write a part of code to pass a specific test. Sometimes code is duplicated or written at a place that is more convenient to pass that test. So a good practice is to clean the code on regular basis and move the newly written code to its appropriate place after testing. There must not be any duplication in the code. With the addition of new features, code gets lengthy. To increase the readability, understanding and maintainability; code is modified that way. Variables, objects and methods are renamed properly. Programmers may rearrange the structure to more logical form. Against each refactoring, tests are rerun which makes the developer confident about existing functionality.
To start a new test, whole cycle is repeated to enhance the functionality. If newly written code doesn’t pass the new test or makes the previously passed tests fail, developer should undo the changes. Instead of making tiny increments in external library code; it is much better to create custom library to test software under test.
Along with the limitations of TDD there are few more challenges:
- Traditional test cases: There are hundreds of traditional test cases which are incompatible with TDD. Need is to prioritize and evaluate those test cases to separate important ones from the waste.
- Writing test cases for a feature again and again in the later stages. Since you have not written the detail oriented test cases because of TDD limitations.
- Before you write test cases for a project in TDD, you should have the know-how and background in development and QA domains.
- Updating existing test cases for a feature again and again in the later stages because of the continuous changes.
Test-driven development allows developers to build the software in small steps. It helps developer to focus on the current task and make the test case pass. Developers then run unit tests to test the developed feature for positive and negative tests to get the expected results. TDD is a popular approach because of its flexibility of rapid change and testable units. However there is more code to write in TDD than without TDD because of the unit test code. TDD is a testing technique to lower the defect density.