With OOAD, the requirement for testing decreased a lot. In former times, people would have said "50% coding, 50% testing". Fortunately, these times have passed, and testing now is only a small part of the overall work, and can be fun for some people. For others, it can be a science, your mileage may vary.
The task of testing written code can be quite different, depending on what is tested. Besides human interaction, there are other possibilities:
- GUI applications and applets need simulated mouse/keyboard events, usually provided by a EventSimulator that replays recorded scenarios. Test suites aren't normally provided with GUI apps, maybe they are too voluminous.
- TUI applications need Simulators that connect to standard I/O streams. Many GNU utilities come with integrated test suites.
- library classes and beans have a defined __class interface__ so that testing can be done by hooking simple test programs to these interfaces.
It is most useful to distribute testing code within __all__ classes, but future installation agents need a way to know where it is, to perform the following actions:
- automagically test a package and reject it if testing fails (or let the user know that it failed asking her to install it anyway),
- possibly strip testing code from the class.
So where to put your testing code? Putting it in main() is a problem for app developers since they need main() as entry point. But main() is nice for beans/classes developers since they can run the compiled bytecode directly to test their code. We propose the following scheme for integrating test code within classes, appliable by both developers
and future installation agents:
- The default place for applet/application test code is in public _static_ boolean _selfTest(void)_. You should provide at least the following behaviour:
- returning true indicates successful testing.
- If you use main() for testing, and the class is __not__ a bean, include "SelfTest-Method: main" in the MANIFEST. The entry "Java-Bean: true" implies automagically "SelfTest-Method: main". The behaviour in the main() case should be:
- calling main (String[] argv), where argv.length == 0, results in starting the SelfTest.
- exiting normally (i.e. return from main or System.exit(0)) indicates successful testing.
- If you provide test code with your class(es) and use another entry point, put it in a method with the signature public _static_ boolean _METHODNAME(void)_, and indicate in your META-INF/MANIFEST file that you have done so with "SelfTest-Method: METHODNAME".
-- RalfStephan, 13-Nov-97, please change to your gusto.
Back to TestingGroup
Content of these pages are owned and copyrighted by the poster.
|
Hosted by:
|
|