I have a java program that runs automatically every morning and contains several methods that are all independent of each other. Sometimes I have to do testing, so I will comment out all of the methods I am not using. This is a problem bc sometimes I forget to uncomment the code and the program may run for a few days without anyone catching on that its not completely running.
Is there any way to set up an automated check for this?
Solution: I have decided to add a counter to count the number methods that run and return an error when the number is wrong.
Auditing for randomly inserted comments? Bad idea.
Use revision control, like Git for your project, if you aren’t already. Then things get really simple:
(if you already use revision control, then look down at #2, and ignore the rest of my answer)
In the above image the ‘Remote repository’ would be where you store the pristine, current development version (no testing-comments).
Set up your unit tests to execute by pulling the latest sources from this repository.
For hacking around, pull yourself a separate copy (in the image ‘Local repository’, and its corresponding ‘Working directory’) and do your commenting/uncommenting/testing there.
Unless you ‘push’ your changes to the ‘Remote repository’, your unit tests will run with the non-commented, clean version available on the ‘Remote repository’.
When you are done testing and have something worthwhile added to the code, commit and ‘push’ to the ‘Remote repository’.
Next time the tests run, they will have the new (good) code.
Profit.
NOTE: ‘Remote repository’ and ‘Local repository’ are really just terms. They can all be on the same machine too.