A really good observation. I just realized that this
technique can be very effectively used in unit testing
existing code. Which is difficult in normal
circumstances.
So,
a) comment out existing functionality that we want to
check before writing any test. b) Then write tests
c) Uncomment only the lines which are affected by the
previously written test.
Any comments?
Nauman:
It might be possible, some of the time. But sometimes
testing existing code means testing a whole bunch of
code together (no simple way about it). I don't see
myself commenting out 50 lines of code just so a test
will fail.
I'd personally only use this if I have specific tests,
not generic ones.
I believe there are actually tools that make these sort
of modifications automatically to the executables, but I
can't recall off hand whether they are for Java or .NET
(i.e. modify bytecode or IL). If I manage to nudge my
memory sufficiently I'll post another comment...