https://github.com/lucaslorentz/minicover
Cross platform code coverage tool for .NET Core
https://github.com/lucaslorentz/minicover
code-coverage coverage dotnet dotnet-cli dotnet-core net-core netcore
Last synced: 6 days ago
JSON representation
Cross platform code coverage tool for .NET Core
- Host: GitHub
- URL: https://github.com/lucaslorentz/minicover
- Owner: lucaslorentz
- License: mit
- Created: 2017-04-15T14:45:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-01-16T09:23:00.000Z (3 months ago)
- Last Synced: 2025-04-12T06:12:46.273Z (6 days ago)
- Topics: code-coverage, coverage, dotnet, dotnet-cli, dotnet-core, net-core, netcore
- Language: C#
- Homepage:
- Size: 702 KB
- Stars: 212
- Watchers: 14
- Forks: 39
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dotnet-core - MiniCover - Minimalist Code Coverage Tool for .NET Core. (Frameworks, Libraries and Tools / Code Analysis and Metrics)
- fucking-awesome-dotnet-core - MiniCover - Minimalist Code Coverage Tool for .NET Core. (Frameworks, Libraries and Tools / Code Analysis and Metrics)
- awesome-dotnet-core - MiniCover - Minimalist Code Coverage Tool for .NET Core. (Frameworks, Libraries and Tools / Code Analysis and Metrics)
- awesome-dotnet-core - MiniCover - 跨平台代码覆盖工具 (框架, 库和工具 / 代码分析和指标)
README
# MiniCover
Code Coverage Tool for .NET Core[](https://dev.azure.com/lucaslorentzlara/lucaslorentzlara/_build/latest?definitionId=3&branchName=master)
[](https://www.nuget.org/packages/MiniCover/)
[](https://coveralls.io/github/lucaslorentz/minicover?branch=master)## Supported .NET Core SDKs
- 8.0 (Global tool or local tool)
- 9.0 (Global tool or local tool)## Installation
MiniCover can be installed as a global tool:
```
dotnet tool install --global minicover
```
Or local tool:
```
dotnet tool install minicover
```## Commands
This is a simplified documentation of MiniCover commands and options.Use `--help` for more information:
```
minicover --help
```**When installed as local tool, MiniCover commands must be prefixed with `dotnet`.** Example:
```
dotnet minicover --help
```### Instrument
```
minicover instrument
```Use this command to instrument assemblies to record code coverage.
It is based on the following main options:
|option|description|type|default|
|-|-|-|-|
|**sources**|source files to track coverage|glob|`src/**/*.cs`|
|**exclude-sources**|exceptions to source option|glob|`**/bin/**/*.cs` and `**/obj/**/*.cs`|
|**tests**|test files used to recognize test methods|glob|`tests/**/*.cs` and `test/**/*.cs`|
|**exclude-tests**|exceptions to tests option|glob|`**/bin/**/*.cs` and `**/obj/**/*.cs`|
|**assemblies**|assemblies considered for instrumentation|glob|`**/*.dll`|
|**exclude-assemblies**|Exceptions to assemblies option|glob|`**/obj/**/*.dll`|*Note 1: Assemblies not related to sources or tests are automatically ignored.*
*Note 2: [Supported syntax](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.filesystemglobbing.matcher?view=dotnet-plat-ext-3.0#remarks) for glob values.*
*Note 3: You can repeat glob options to represent multiple values. Example: `--sources "a/**/*.cs" --sources "b/**/*.cs"`*
This command also generates a **coverage.json** file with information about the instrumented code.
### Uninstrument
```
minicover uninstrument
````Use this command to revert the instrumentation based on **coverage.json** file.
**Make sure you call uninstrument before publishing or packing your application.**
### Reset
```
minicover reset
````Use this command to reset the recorded coverage so far.
### Report
```
minicover report
````Use this command to print a coverage report in the console.
The command exits with failure if the coverage doesn't meet a specific threshold (90% by default).
### More commands
- **cloverreport**: Write an Clover-formatted XML report to file
- **coberturareport**: Write a cobertura XML report to file
- **coverallsreport**: Prepare and/or submit coveralls reports
- **htmlreport**: Write html report to folder
- **opencoverreport**: Write an OpenCover-formatted XML report to file
- **xmlreport**: Write an NCover-formatted XML report to fileUse `--help` for more information.
## Build script example
```shell
dotnet restore
dotnet build# Instrument
minicover instrument# Reset hits
minicover resetdotnet test --no-build
# Uninstrument
minicover uninstrument# Create html reports inside folder coverage-html
minicover htmlreport --threshold 90# Console report
minicover report --threshold 90
```## Ignore coverage files
Add the following to your .gitignore file to ignore code coverage results:
```
coverage-html
coverage-hits
coverage.json
```## Libraries
When using MiniCover libraries:
- use dependency injection to create instances
- use only the main interfaces listed on each package belowBy doing that, you reduce the risk of being impacted by future MiniCover changes.
### MiniCover.Core
Main MiniCover operations.
Dependency injection configuration:
```C#
services.AddMiniCoverCore();
```Main interfaces:
- IInstrumenter
- IUninstrumenter
- IHitsReader
- IHitsResetter### MiniCover.Reports
MiniCover reports.
Dependency injection configuration:
```C#
services.AddMiniCoverCore();
services.AddMiniCoverReports();
```Main interfaces:
- ICloverReport
- ICoberturaReport
- IConsoleReport
- ICoverallsReport
- IHtmlReport
- IHtmlSourceFileReport
- INCoverReport
- IOpenCoverReport