All Projects → Tyrrrz → Githubactionstestlogger

Tyrrrz / Githubactionstestlogger

Licence: mit
Test logger for .NET that reports results in a format that GitHub Actions understands

GitHubActionsTestLogger

Build Coverage Version Downloads Donate

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

diff

Usage

Installation

To use GitHubActionsTestLogger, follow these steps:

  1. Install GitHubActionsTestLogger package in your test project
  2. Install Microsoft.NET.Test.Sdk package in your test project (or update to latest)
  3. Modify your GitHub Actions workflow file by adding --logger GitHubActions to dotnet 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 named TRAIT_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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].