Customizing Static Analysis
You can customize Jtest's static analysis feature by:
- Enabling/disabling specific rules.
- Enabling/disabling rule categories
- Customizing built-in rules.
You can also use the RuleWizard feature to create custom coding standards; for more information on this feature, see Creating Your Own Static Analysis Rules.
Enabling/Disabling Specific Rules
One way to control what rules are enforced is to enable/disable individual rules. If you do this, be aware that Jtest looks for violations of a rule only if the rule is enabled and its severity level is enabled.
- View which rules are currently enabled/disabled.
- Open the Global Test Parameters window by clicking the Global button.
- In the Global Test Parameters window, go to Static Analysis> Rules.
- Open the Built-in Rules node or User Defined Rules node.
- Open the node for the category of rules that you want to view.
- Enable/disable rules by right-clicking the appropriate rule and choosing the appropriate command (either Enable or Disable) from the shortcut menu.
Enabling/Disabling Rule Categories
Each rule has two categories:
- The descriptive category that describes the type of rule (for example, Servlets, Design by Contract, Initialization, User Defined Rules, etc.)
- The severity category that describes the severity of a violation of the rule (violations of coding standards that are most likely to cause an error are level 1; violations of coding standards that are least likely to cause an error are level 5). By default, Jtest reports violations of all coding standards with a severity level of 1, 2, or 3. A rule's severity is indicated by the final character in each rule code, as indicated in the Global Test Parameters window's Static Analysis> Rules> Built-in Rules node. For example, PB.SBC has a severity level of 1, and OOP.IIN has a severity level of 5.
To enable/disable all rules in a certain descriptive category:
- Open the Global Test Parameters window by clicking Global.
- Right-click the Static Analysis> Rules> <name_of_rule_category> node. A shortcut menu will open.
- Choose Enable All or Disable All from the shortcut menu.
To enable/disable rule all rules in a certain severity categories:
- Open the Global Test Parameters window by clicking Global.
- Open the Severity Levels Enabled node (beneath Static Analysis> Rules).
- Enable/disable categories by right-clicking a category whose status you want to change and choosing Enable or Disable from the shortcut menu.
You can also enable/disable severity categories at the class and project level. You might want to do this, for example, if you generally want to enforce only the most severe rules, but you want to enforce all rules for a specific class. To enable/disable rules at the class or project level, set the Severity flags in Class Test Parameters - Static Analysis (if you are testing a single class) or Project Test Parameters - Static Analysis (if you are testing a set of classes).
Customizing Rules
You can customize three types of rules:
- Rules saved in <Jtest_install_dir>/brules.
- Naming conventions.
- Class metrics rules.
Customizing Rules with RuleWizard
You can customize any rule available in <Jtest_install_dir/brules> with RuleWizard.
To access RuleWizard, right-click the Rules button in either Jtest UI, then choose Launch RuleWizard from the shortcut menu.
The RuleWizard UI will then open. The RuleWizard User's Guide (accessible by choosing Help> View in the RuleWizard UI) contains information on how to create, enforce, and enable/disable custom rules.
You can also edit Naming Convention rules and Metrics rule from the Jtest Global Test Parameters tree.
Customizing Naming Conventions
To edit what naming convention is enforced:
- Locate the rule that you want to modify in the Global Test parameters tree.
- Right-click the rule, then choose Edit Regular Expression from the shortcut menu.
- Modify the regular expression in the dialog box that opens.
- Click OK to save your changes.
If you want the naming convention to apply only to certain modifiers (e.g., public, protected, package, private):
- Locate the rule that you want to modify in the Global Test parameters tree.
- Right-click the rule, then choose Edit Optional Modifier from the shortcut menu.
- Enter the appropriate modifiers in the dialog box that opens (If you are entering multiple modifiers, use a space character to separate the modifiers' names).
- Click OK to save your changes.
Customizing Class Metrics
To edit the upper and lower thresholds for a class metric:
- Locate the metric rule that you want to modify in the Global Test parameters tree.
- Right-click the rule, then choose Modify Upper Threshold or Modify Lower Threshold from the shortcut menu.
- Modify the threshold in the dialog box that opens.
- Click OK to save your changes.
Related Topics
About Static Analysis
Performing Static Analysis
Creating Your Own Static Analysis Rules
Viewing Class and Project Metrics
|