Important announcement

Dear visitor,

Please note that this OpenCourseWare platform will be replaced at the end of 2026 by a new platform (under the same url ocw.tudelft.nl).

Courses and their contents that are currently available the platform will partly be migrated. URL’s for this content will change and content might be unavailable for some time. In addition, some courses will not be available anymore.

If you are linking to specific courses on this platform (for instance for your students), please take timely measures to avoid problems with access. Possible actions are:

  • Download the materials to your local platform (laptop, server)
  • For educators only (including TU Delft lecturers): Contact us at ocw@tudelft.nl and inform us what course you are using in what context (institute, program, period of use, number of students). We will research (in collaboration with the authors of the course) and decide if we will migrate the course, and if yes, can supply you with a new url.

Thank you.

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:

    1. Go to the LeapYear production class (which is in the nl.tudelft.ontesting.leapyear package).
    2. Change the last return line from:
      return  ( year % 4 == 0 ) ? true : false;
      to
      return  ( year % 4 == 0 ) ? false : true;
    3. 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!
    4. 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.
    5. 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!
Creative Commons License
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/.
Back to top
[sg_popup id=6]