2.2.4 Hands-on: Simulating a bug
Course subject(s)
Module 2. Functional Testing
In practice, developers often change their source code during different maintenance tasks: when implementing a new feature, when refactoring, when trying to improve the performance of the algorithm, etc.
It is not hard to see that, whenever we change our code, we should test the entire system again. And that’s when having automated tests becomes handy. Let’s simulate a bug in our LeapYear implementation:
-
- Go to the LeapYear production class (which is in the nl.tudelft.ontesting.leapyear package).
- Change the last return line from:
return ( year % 4 == 0 ) ? true : false; to
return ( year % 4 == 0 ) ? false : true;
- Notice how honest this mistake is. We just inverted the true and the false. These small mistakes are so common in the daily life of a developer!
- However, as know we have an automated test suite that we can just run whenever we want, let’s do it. Run the tests in LeapYearTest class.
- Two of our tests fail! And this is actually a good thing: now you know that your implementation does not work as expected, and you can fix it before going to production. One less bug for the user to complain!
Automated Software Testing: Practical Skills for Java Developers by TU Delft OpenCourseWare is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://online-learning.tudelft.nl/courses/automated-software-testing-practical-skills-for-java-developers/.