Test Driven Development and Testing Challenges
- June 23, 2016
Testing software before launching it in the market has become more than just a trend. It has become the need of the time due to cyber threats present on the internet. Where the software development market keeps establishing tips for better software development, the software testing industry has started giving out information as well.
When it comes to software testing, test cases are a lot of more than just a step on the journey; they are the backbone of the whole testing process. Let’s discuss one of the most famous techniques used for test case development. Test-driven development (TDD) is also called test-driven design and is widely used by every mobile application testing company. 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).
A lot of companies like to build software in lesser time with the same efficiency and good results. We are sure you would like that as well. 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 the 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 are reduced at later stages.
However, where test-driven development has a lot of benefits to offer to the industry, it has some drawbacks as well. One limitation of TDD is tester can sometimes apply tests incorrectly. And this may result in software units malfunction in the real world. User may encounter scenarios which are not implemented by the developer, nor tested by the tester. This usually makes the user send the software back for edits, which, to be honest, is not good for the reputation of the company.
Test Driven Development Cycle
Now, that you are aware of all the details of TDD, it is time for you to learn about its life cycle. It will help you see how you can use it in the future if needed. Here are the basic steps that every company follows when using TDD:
1. Adding a Test
The very beginning of a feature is writing a test that can define the functionality or improvements in functionality and which should be very clear and expressive. The 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.