GitHub Actions Test Logger

repository·prime·Indexed 43 days ago

https://github.com/tyrrrz/githubactionstestlogger

An extension for VSTest and Microsoft.Testing.Platform that integrates test results into GitHub Actions via job annotations, code diff highlights, and detailed job summaries. It supports custom annotation formatting using replacement tokens and provides configuration options for managing test summaries and passed/skipped test visibility.

Tokens
1.5K
Snippets
10
Records
12
Agent score
55%

What's inside GitHub Actions Test Logger

  1. Use GitHub Actions Test Logger with VSTest

    prime

    To use the reporter with VSTest, add the --logger GitHubActions option to your test command.

    Important Compatibility Notes

    • xUnit v3: Replace the xunit.v3 package reference with xunit.v3.mtp-off to avoid conflicts with the built-in MTP dependency in the base package.
    • Peer Dependency: It is highly recommended to install the latest version of Microsoft.NET.Test.Sdk in your test project.
    • Legacy .NET SDK: If using .NET SDK v2.2 or lower, you must set <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in your test project.
    • Package Visibility: Unlike the MTP mode, you can mark the GitHubActionsTestLogger package reference as private using PrivateAssets="all" when using VSTest.
    run: dotnet test --configuration Release --logger GitHubActions
  2. Use GitHub Actions Test Logger with Microsoft.Testing.Platform

    prime

    When using Microsoft.Testing.Platform, the reporter is automatically detected and registered when running in a GitHub Actions environment. You can also enable it manually using the --report-github option.

    Important Compatibility Notes

    • xUnit v3: Replace the xunit.v3 package reference with xunit.v3.mtp-v2. The standard xunit.v3 uses MTP v1, which is incompatible.
    • Peer Dependency: It is highly recommended to install the latest version of Microsoft.Testing.Platform in your test project.
    • Package Visibility: Do not mark the GitHubActionsTestLogger package reference as private (e.g., do not use PrivateAssets="all"), as it must be included in the build output.
    run: dotnet test --configuration Release --report-github
  3. Collect source information for VSTest

    prime

    By default, VSTest does not collect source information, so the extension relies on stack traces to extract it for failed tests. To improve accuracy, instruct the runner to collect source information by adding RunConfiguration.CollectSourceInformation=true as an argument after a double dash (--).

    Alternatively, you can enable this in a .runsettings file.

    run: >
      dotnet test
      --configuration Release
      --logger GitHubActions
      -- 
      RunConfiguration.CollectSourceInformation=true
  4. Configure Microsoft.Testing.Platform reporter options

    prime

    When using Microsoft.Testing.Platform, customize the reporter by passing arguments prefixed with --report-github-.

    run: >
      dotnet test
      --configuration Release
      --report-github
      --report-github-annotations-title @test
      --report-github-annotations-message @error
  5. Reference: GitHub Actions Test Logger configuration options

    prime

    The following options are available to customize the reporter behavior. The syntax differs by runner:

    Option (MTP)Option (VSTest)Description
    --report-github-annotations-titleannotations-title=Sets the annotation title format.
    --report-github-annotations-messageannotations-message=Sets the annotation message format.
    --report-github-summary-allow-emptysummary-allow-empty=Whether to include empty test runs in the summary. (Default: false)
    --report-github-summary-include-passedsummary-include-passed=Whether to include passed tests in the summary. (Default: true)
    --report-github-summary-include-skippedsummary-include-skipped=Whether to include skipped tests in the summary. (Default: true)