Tyrrrz / Githubactionstestlogger
GitHubActionsTestLogger
✅ Project status: active.
Custom logger for dotnet test
that reports test results in a structured format that GitHub Actions understands.
When using this logger, failed tests are listed in workflow annotations and highlighted in code diffs.
Download
📦 NuGet: dotnet add package GitHubActionsTestLogger
Screenshots
Usage
Installation
To use GitHubActionsTestLogger, follow these steps:
- Install
GitHubActionsTestLogger
package in your test project - Install
Microsoft.NET.Test.Sdk
package in your test project (or update to latest) - Modify your GitHub Actions workflow file by adding
--logger GitHubActions
todotnet test
:
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Install .NET
uses: actions/[email protected]
with:
# Note: version 3.0.x or higher is required!
dotnet-version: 5.0.x
- name: Build & test
# Specify custom logger here
run: dotnet test --configuration Release --logger GitHubActions
⚠️ Ensure that you are running your tests with .NET SDK v3.0 or higher. Older versions of the SDK don't support custom test loggers added via NuGet packages.
⚠️ Ensure that your test project references Microsoft.NET.Test.Sdk
version 16.8.0
or higher.
Older versions of this package may not work properly with custom test loggers.
Options
GitHubActionsTestLogger has a few options that you can override to customize its behavior.
In order to pass an option to the logger, include it as an additional parameter inside --logger
:
dotnet test --logger "GitHubActions;option1=foo;option2=bar"
format
Specifies the format used when logging test results to the console.
The following replacement tokens are available:
-
$test
-- replaced with the display name of the test -
$outcome
-- replaced with the error message (in case of an exception) or the outcome of the test -
$traits.TRAIT_NAME
-- replaced with the value of a trait namedTRAIT_NAME
Default: $test: $outcome
.
Examples:
-
$test: $outcome
->MyTests.Test1: AssertionException: Expected 'true' but found 'false'
-
[$traits.Category] $test: $outcome
->[UI Tests] MyTests.Test1: AssertionException: Expected 'true' but found 'false'
report-warnings
Specifies whether to report warnings for tests that have neither failed nor succeeded (i.e. skipped or inconclusive). If disabled, only errors that represent failed tests will be logged and all other tests will be ignored.
Can be set to either true
or false
.
Default: true
.