The Coverage Statistics view (see Figure 8) provides information on which methods were used (and therefore tested, at least to some extent) by the test cases you just ran. The coverage statistics are a nice feature, although they don't provide the same level of detail as dedicated coverage tools such as Cobertura, Clover, and jcoverage, which provide line-precision coverage data as well as statistics on both line and branch coverage. Nevertheless, it does have the advantage of providing real-time coverage results, and currently, only commercial-code coverage tools such as Clover and jcoverage provide both line-level coverage reporting and full IDE integration.
Figure 8: The Coverage Statistics view
Static Analysis Tools
Another interesting item in the TPTP tool box is the static analysis tool. Java static analysis tools such as PMD allow you to automatically verify code quality by checking it against a set of predefined rules and best practices for the code. TPTP now includes a static analysis tool as well. In addition to providing a set of static analysis rules of its own, this tool is designed to provide a consistent interface in which other tool vendors can integrate their own rules.
To run static analysis on your code, you need to create an analysis configuration. Open the Analysis window using the contextual menu in the Java view or the Analysis icon, which should now appear on the toolbar (see Figure 9). An analysis configuration determines what code will be analyzed (Scope), and what rules should be applied (Rules). There are 71 rules to choose from, such as "Avoid casting primitive types to lower precision" and "Always provide a break at the end of every case statement." You can also use predefined rule sets such as "Java Quick Code Review" (in which only 19 of the 71 rules are applied).
Figure 9: Setting up static analysis rules
To analyze your code, use the Analysis icon in the toolbar. Analysis isn't done in real time, as it is with some of the other similar tools such as Checkstyle. However, the results are clearly presented (see Figure 10): errors are bookmarked in the source code view and listed in the Analysis Results view in a tree view organized by error type. One neat feature is the "Quick Fix" option, which appears in the contextual menu over certain error types, and which proposes, if possible, to automatically correct the problem for you.
Figure 10: Static code analysis results
The Eclipse Test & Performance Tools Platform is a valuable addition to the Eclipse IDE toolkit. The wide range of performance testing it allows will help you to guarantee high-quality and high-performance code right from the first unit tests.
TPTP is certainly not as developed as some of the commercial tools available such as OptimizeIt and JProbe, which often have more sophisticated reporting and analysis functionalities, and a more polished presentation. However, commercial profiling tools tend to be notoriously expensive, and it is often difficult justifying their use in all but the most dire of circumstances. Although it is still relatively young, TPTP is a powerful and capable product, and can certainly provide valuable profiling data that many projects would otherwise have to do without.
John Ferguson Smart is a freelance consultant specializing in Enterprise Java, Web Development, and Open Source technologies, currently based in Wellington, New Zealand.
Return to ONJava.com.