I am a one-man development team at the moment and I want to be sure that
my code is going to be considered thoroughly tested when I eventually
release it.
I think the biggest win comes from automated regression testing.
IME its well worth the effort of writing a scriptable regression test
harness for any chunk of code that's more complex than, say, a package
that writes and parses CSV files. Done right, the code is relatively
simple and can be used to implement a whole bunch of tests merely by
writing a well thought out set of scripts.
Think about capturing human-readable test output so that the test harness
can compare this with the expected results. Design the scripts to be self
documenting and easy to understand: allowing comments in them is an
enormous help. Design the harness so its output lists the script with
interspersed test results. This makes debugging much easier.
Ideally it will output a single line reporting a successful test and show
understandable diagnostics if the test fails. Just comparing test output
with expected output and displaying the differences can do this if you
design the test output to be readable.
A well written regression test setup will accept a single, simple command
will that runs the entire set of tests and produces a small, unambiguous
report that can indicate pass/fail at a glance. Do this and you'll tend
to run regression tests after any and all code changes. The effect on
code reliability can be dramatic.
Write the tests from the code specifications. The effort of writing a
clear specification is never wasted. Write it hierarchically so it has an
overview, class and method descriptions. This pays off in:
- better code
- more complete test coverage
- the specification can be turned into javadocs.
Some guidance on what should be tested and how thoroughly it should be
tested - as well as what does NOT need to be tested - would be very
helpful.
See above, but you need a decent specification as the basis for test
coverage. Develop a test set that covers all specified functions in terms
of correct functioning, corner cases and error handling. Its essential to
write tests from the specification, not the code or you'll just end up
testing what the code does, not what its meant to do. There is a good
case for writing the test harness and scripts before you start coding
because this way you may spot errors in the specification and will
certainly avoid writing tests for the code you actually wrote.
Never write code that can't be tested. Design it with this in mind.