Skip to content

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

License

Notifications You must be signed in to change notification settings

y0m1g/GitHubActionsTestLogger

 
 

Repository files navigation

GitHub Actions Test Logger

Build Coverage Version Downloads Discord Donate Fuck Russia

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.

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! 🇺🇦

Download

📦 NuGet: dotnet add package GitHubActionsTestLogger

Screenshots

diff

Usage

Installation

To use GitHub Actions Test Logger, 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:
          dotnet-version: 5.0.x

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

⚠️ 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.

⚠️ If you are using .NET SDK v2.2 or lower, you need to enable <CopyLocalLockFileAssemblies> property in your test project.

Options

GitHub Actions Test Logger 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 additionally report warnings for tests that have neither failed nor succeeded (i.e. skipped or inconclusive). If disabled, only failed tests will be reported.

Can be set to either true or false.

Default: true.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%