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

Tools of the trade, Part 2

Jtest statically and dynamically analyzes your Java code

  • Print
  • Feedback

Page 3 of 7

Figure 1. Jtest's Class Testing UI consists of a menu bar, a toolbar, a Class Name panel, a Test Progress panel, an Errors Found panel, and a status bar. Click on thumbnail for full-size image.

Note
For simplicity, all this article's static/dynamic analysis examples use the Class Testing UI.


Use the Project Testing UI to test a project's set of classes. This UI consists of a menu bar, a toolbar, a Project Testing UI Controls panel, a Results panel, and a status bar. Though similar to their Class Testing UI counterparts, the menu bar, toolbar, and status bar are specific to the Project Testing UI. For example, File's Open menu item lets you open an existing project test parameter's .ptp file, and that file's name and location appear in the status bar. A project test parameter is a configurable test setting that applies to a specific set of classes. The Project Testing UI Controls panel and Results panel distinguish the Project Testing UI from the Class Testing UI:

  • Project Testing UI Controls panel: The Project Testing UI Controls panel lets you identify a project by its location and choose those classfiles to test (via a filtering mechanism). This panel also reports basic data, such as number of classes tested and number of errors found, about a project test.
  • Results panel: The Results panel expands on the Class Testing UI's Errors Found panel by displaying test results on a class-by-class basis and letting you graph various test results, such as errors per class, over time.


Figure 2 illustrates the various GUI elements that compose the Project Testing UI.

Figure 2. Jtest's Project Testing UI consists of a menu bar, a toolbar, a Project Testing UI Controls panel, a Results panel, and a status bar. Click on thumbnail to view full-size image.

Tip
To view a professional report of test results (after the current test session's various static and/or dynamic analysis tests complete), choose the Report menu item from the View menu.


Perform static analysis

Static analysis examines executable code or equivalent source code to learn if that code conforms to industry-standard guidelines. Jtest performs static analysis by comparing executable code or the equivalent parsed source code with coding rules that represent more than 300 guidelines. Because research suggests code written to industry-standard guidelines has a lower probability of defects than code that does not follow those guidelines, any deviation from the guidelines suggests a potential defect. Jtest reports deviations as errors in either the Errors Found panel (for the Class Testing UI) or the Results panel (for the Project Testing UI). Furthermore, Jtest's editor highlights source code lines where deviations occur.

Let's perform a static analysis of last month's Lines project. If you recall, that applet project consisted of a single Lines.java source file (which produces a single Lines.class classfile). We use the Class Testing UI to perform the analysis. Complete the following steps to statically analyze Lines:

  • Print
  • Feedback

Resources