Introduction
You can configure Eclipse to collect coverage information for JUnit tests or Java applications when a run configuration is executed. This section describes how to enable collecting coverage for JUnit tests. For information about collecting coverage for Java applications, see Collecting Coverage for Java Applications in Eclipse.
Selecting a Launcher
- Ensure that Jtest DTP Engine is enabled and properly configured; see Enabling and Configuring the DTP Engine for details.
- Choose Run> Run Configurations in the Eclipse menu bar.
- Select a run configuration and click the Select one... link at the bottom of the page.
- Enable the Use configuration specific settings option and select Jtest JUnit Proxy Launcher.
- Click OK.
Enabling Collecting Coverage
- Choose Run> Run Configurations... to open the Run Configurations dialog.
- Select a configuration and click the Jtest tab.
- Select the Enable coverage option to activate collecting coverage. This option is enabled by default.
- (Optional) Select the Enable Unit Test Assistant option to run your tests with Unit Test Assistant, which can help you improve the test quality. See Creating, Analyzing and Enhancing Tests with Unit Test Assistant for more information.
- Click Apply.
Customizing Coverage Scope
By default, coverage is collected and reported for the project that includes the tested class and its depending projects. The projects included in the scope are displayed in the Included Projects field in the Jtest tab.
You can narrow the coverage scope to include only the items selected in your Eclipse Package Explorer or to exclude specified classes.
Reporting Coverage for Selected Items
To collect coverage data for only the items selected in the Package Explorer view of your IDE.
- Choose Run > Run Configurations... to open the Run Configurations dialog.
- Select a configuration and click the Jtest tab.
- Enable the Report coverage for selection only option.
- Click Apply.
The Included Projects field will be disabled and coverage will be reported only for the items selected in the Package Explorer.
Excluding Classes from Instrumentation
You can specify which classes should not be included in the coverage scope.
- Choose Run > Run Configurations... to open the Run Configurations dialog.
- Select a configuration and click the Jtest tab. The Exclude field defines which packages should be excluded.
- Click New to specify the patterns for excluding packages. You can manually enter a pattern or use the browsing interface to find packages.
- Click Apply.
Examples of Exclude Patterns
If you specify exclude patterns manually, use the *
wildcard to exclude all the classes that are included directly in a given package.
examples/*
- Matches all classes directly in theexamples
package (e.g.examples.Foo
). Theexamples.internal.Foo
class will NOT be excluded with this pattern.examples/Foo*
- Matches all classes in theexamples
package whose class file names start with "Foo" (e.g.examples.FooFile
). Theexamples.internal.FooFile
class will NOT be excluded from the scope, as it belongs to another package.
Viewing Coverage
You can view coverage for the executed code with the Coverage view (see Viewing Coverage).