Sometimes you do not need to know code coverage data solution-wide. For example, you may not be interested in coverage statistics for code marked with
ObsoleteAttribute or a specific legacy project. In this case, you can set coverage filters based on namespace, project, type, type member, or attribute.
By default, dotCover provides built-in filters for assemblies from other solutions and system assemblies. You cannot view or edit these filters. However, if you need to disable these filters, use the Predefined coverage filter option on the page of dotCover options.
Viewing and modifying coverage filters
There are two scopes for coverage filters:
- All Solutions - global filters that apply to all solutions in your computer.
- Current Solution - per-solution filters that apply to the current solution. You can share these filters with your team; see Sharing coverage filters for details.
You can view and edit coverage filters in the Coverage Filters dialog . To open this dialog, do one of the following:
- Visual Studioで、 Ctrl+Alt+K F を押すか、メインメニューから を選択します
- dotCoverスタンドアロンアプリケーションでは、 Ctrl+Alt+K F を押すか、メニューの を選択します。
When you open this dialog, you can see filters in both scopes. If no solution is opened, the dialog shows only global filters.
By default, dotCover provides one global filter for excluding code items by the
ExcludeFromCodeCoverageAttribute attribute. If necessary, you can enable/disable, modify or remove it.
To view and modify current coverage filters
- Coverage Filters dialogを開きます。
- Use the グループ selector to change the grouping of filters - by scope or by kind.
- To enable or disable a filter, use the check box next to it.
- To remove a filter, select it in the list and click 削除
- To edit a filter, select it in the list and click 編集 . In the Edit Coverage Filter dialog that appears, make necessary changes as described for adding a new filter below.
- Click 保存 to save and apply your modifications, if any.
Adding new coverage filters
To add a new coverage filter
- Coverage Filters dialogで、フィルターの追加をクリックします。
- In the Add Coverage Filter dialog that appears, choose the type of filter rule:
- Analyze code in - to include the specified code item into code coverage analysis and exclude all other code items.
- Do not analyze code in - to exclude the specified code item from code coverage analysis.
- Do not analyze code marked with attribute - to exclude code items with the specified attribute from code coverage analysis.
- If you have chosen one of the first two options, specify an assembly, a class, and/or a method to be included or excluded in the coverage analysis. Code items are filtered independently on one another. For example, if you specify a method and leave asterisks (*) for assembly and class to exclude methods with the specified name from all assemblies and all classes.
You can use asterisk wildcards when specifying code item names in a filter: '*' (asterisk) represents zero or more characters.
For example, you can use the
*.Testswildcard that will exclude all test projects from code analysis.
- If you have chosen the last option, specify the name of the attribute that will be used to exclude symbols from the coverage analysis. Optionally, specify the assembly name where this attribute is declared.
- In the Apply filter to section, specify the scope of the filter: All solutions or Current solution.
- Click [OK] to finish adding the filter.
- In the カバレッジフィルタ dialog, click 保存 to save and apply your modifications.
Sharing coverage filters
Solution-wide filters are saved in the Solution team-shared settings layer and, therefore, can be shared within other developers who work on this solution.
In fact, all you need to do to share solution-wide filters is to put the [SolutionName] .sln.DotSettings file in your solution folder under a version control system (VCS). As soon as other team members get this file from VCS the filters will be applied on their computers as well.
Note that other JetBrains products that integrate into Visual Studio may store their solution-wide team-shared settings in the same file. Therefore, if you put this file under VCS, bear in mind that other product's settings may be shared as well. For more information, see dotCover設定の管理と共有 .
Other ways of filtering and searching coverage results
Besides setting up coverage filters in the Coverage Filters dialog , dotCover provides the following ways of filtering and searching coverage results;
- You can add temporary filters when you are running coverage analysis for external applications
- You can disable some unit tests by categories. To do so, specify the categories that you want to disable in the Don't run tests from categories field on the page of dotCover options.
- If you analyze coverage of unit tests using the ユニットテストカバレッジ window, you can edit coverage filters by clicking the Edit Coverage Filters... button.
- You can exclude nodes form the current presentation of the coverage snapshot after coverage analysis. Note that the 選択したノードを除外してカバレッジフィルタを作成する command allows creating a coverage filter automatically for the selected item.
- You can search code coverage tree to display only the items that match the search expression.