Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

"Runnability" testing of Java programs

A unique aspect of Java technology is that programs can run anywhere without recompilation. Here's how to test your programs so that you can find any runnability problems before your customers do

  • Print
  • Feedback

Page 6 of 7

The testing process

Testing, which requires supplying input to the program being tested and then examining the results, may be performed at all levels of program development -- from unit tests for individual classes or methods (structural testing) to system or usability tests at the outermost layer of the program (functional testing). Runnability testing is likely to occur at the outer levels of the program, because it is by nature a test of the integrated product -- and because runnability problems often don't show up in an isolated piece of the program.

Although, fundamentally, runnability testing is functionality testing, and can be done entirely from outside the program, it's also useful to delve into the interior of a program during the test. For example, it may be efficient to take control of an interior component module of a program in order to exercise it more directly than can be done by exercising the integrated product. It may also be useful to insert a probe into the interior of a program, to help diagnose problems that may be masked in the integrated product.

When it comes to testing, a big advantage of Java technology is that it is quite easy to write and maintain this kind of into-the-box code. Because Java programs are linked on demand, at runtime, the test probe can be inserted without recompiling or relinking the rest of the program.

Earlier, we discussed some of the reasons a Java program may fall short of the write-once, run-anywhere goal. Below, we explore some ideas about how to efficiently screen for these shortcomings. Your tests for Java program runnability should have the following properties.

Robustness testing

A program is said to be robust if it successfully completes its job even when it encounters unanticipated circumstances, as a result of some input data or execution environment anomalies. Note that runnability testing is essentially robustness testing. We make the fundamental assumption that functionality testing has been successfully completed and we know what the program is supposed to do. Further, we know how to measure what it has done. The challenge of runnability testing is to ascertain that the tested program fulfills its function on other JRE implementations -- in other words, that the program is robust against platform variations.

Note that this is slightly different from testing that your program does the same thing on every platform. It is entirely possible that the program specification implies that your program, in order to be correct, should behave differently on a different platform. A simple example is:

    class WhatOS {
        public static void main(String[] args) {
            String osName =System.getProperty("os.name");
            System.out.println(osName);
        }
    }


The above program is runnable in any Java environment, but clearly it produces different results on different platforms. A more subtle example is window displays and layouts, the details of which are likely to be platform dependent even though the intention and functionality is the same.

  • Print
  • Feedback

Resources
  • Java Testing Tools from Sun include JavaStar GUI capture-replay, with the ability to write predicates that use the real Java objects; JavaScope, coverage measurement for Java programs; JavaSpec, a tool for creating method-level test programs; JavaLoad, stress testing for Java programs; JavaLoom, a static analyzer for thread behavior; and JavaPureCheck, a checker for portability of Java programs http://www.sun.com/suntest
  • James Gosling, Bill Joy, and Guy Steele, The Java Language Specification, Addison-Wesley 1996 http://java.sun.com/docs/books/jls/
  • Tim Lindholm and Frank Yellin, The Java Virtual Machine Specification, Addison-Wesley, 1996 http://java.sun.com/docs/books/vmspec/
  • Boris Beizer, Software Testing Techniques, 2nd Edition, Van Nostrand Reinhold, 1990 http://www.faqs.org/faqs/software-eng/part3/section-13.html
  • G. Rothermel and M. J. Harrold, "Selecting Regressions Tests for Object-oriented Software," Proceedings of the Conference on Software Maintenance, IEEE Computer Society Press, 1994, pp. 14-25 http://www.computer.org/
  • R. M. Poston, "Automated Testing from Object Models," Communications of the ACM, 1994, 37 (9), pp. 48-58 http://www.acm.org/pubs/
  • D.E. Perry and G.E. Kaiser, "Adequate Testing and Object-oriented Programming," Journal of Object-oriented Programming, 1990, 2 (5), pp. 13-19 http://www.sigs.com/publications/joop/
  • Roger Hayes, 100% Pure Java Cookbook, Sun Microsystems Inc. 1998 http://java.sun.com/100percent/cookbook.html