GitHubActionsTestLogger icon indicating copy to clipboard operation
GitHubActionsTestLogger copied to clipboard

.NET test logger that reports to GitHub Actions

GitHub Actions Test Logger

Made in Ukraine Build Coverage Version Downloads Discord Donate Fuck Russia

🟑 Project status: maintenance mode[?]

Custom logger for dotnet test that integrates with GitHub Actions. When using this logger, failed tests are listed in job annotations and highlighted in code diffs. Additionally, this logger also generates a job summary that contains detailed information about the executed test run.

Terms of use[?]

By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all the following statements:

  • You condemn Russia and its military aggression against Ukraine
  • You recognize that Russia is an occupant that unlawfully invaded a sovereign state
  • You support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas
  • You reject false narratives perpetuated by Russian state propaganda

To learn more about the war and how you can help, click here. Glory to Ukraine! πŸ‡ΊπŸ‡¦

Install

  • πŸ“¦ NuGet: dotnet add package GitHubActionsTestLogger

Screenshots

annotations summary

Usage

Installation

To use GitHub Actions Test Logger, follow these steps:

  1. Install GitHubActionsTestLogger package in your test project
  2. Update Microsoft.NET.Test.Sdk package in your test project to the latest version
  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/checkout@v3

      - name: Install .NET
        uses: actions/setup-dotnet@v2
        with:
          dotnet-version: 6.0.x

      - name: Build & test
        run: dotnet test --configuration Release --logger GitHubActions

Warning: Ensure that your test project references Microsoft.NET.Test.Sdk version 17.2.0 or higher. Older versions of this package may not work properly with custom test loggers.

Warning: If you are using .NET SDK v2.2 or lower, you need to set the <CopyLocalLockFileAssemblies> property to true in your test project. Learn more.

Options

GitHub Actions Test Logger has 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;annotations.titleFormat=$test;annotations.messageFormat=$error"

annotations.titleFormat

Specifies the format of the annotation title used when reporting test failures.

The following replacement tokens are available:

  • $test β€” replaced with the display name of the test
  • $traits.TRAIT_NAME β€” replaced with the value of the trait named TRAIT_NAME
  • $error β€” replaced with the error message
  • $trace β€” replaced with the stack trace
  • $framework β€” replaced with the target framework

Default: $test.

Examples:

  • $test β†’ MyTests.Test1
  • [$traits.Category] $test β†’ [UI Tests] MyTests.Test1
  • $test ($framework) β†’ MyTests.Test1 (.NETCoreApp,Version=v6.0)

annotations.messageFormat

Specifies the format of the annotation message used when reporting test failures. Supports the same replacement tokens as annotations.titleFormat.

Default: $error.

Examples:

  • $error β†’ AssertionException: Expected 'true' but found 'false'
  • $error\n$trace β†’ AssertionException: Expected 'true' but found 'false', followed by stacktrace on the next line