XUnit.Otel.Template 1.0.0

dotnet new install XUnit.Otel.Template::1.0.0                
This package contains a .NET Template Package you can call from the shell/command line.

XUnit.Otel.Template

Build CodeQL NuGet Conventional Commits License

alt

Template with OpenTelemetry test instrumentation for XUnit.

Installation

dotnet new install XUnit.Otel.Template

Usage

Find template:

❯ dotnet new list xunit-otel
# These templates matched your input: 'xunit-otel'

# Template Name  Short Name  Language  Tags
# -------------  ----------  --------  -------------------------
# XUnit Otel     xunit-otel  [C#]      XUnit/Tests/OpenTelemetry

Verify output:

❯ dotnet new xunit-otel -o $dev/XUnitOtelExample01 -n XUnitOtelExample --dry-run
# File actions would have been taken:
#   Create: $dev\XUnitOtelExample01\BaseFixture.cs
#   Create: $dev\XUnitOtelExample01\Directory.Packages.props
#   Create: $dev\XUnitOtelExample01\ExampleTests.cs
#   Create: $dev\XUnitOtelExample01\Extensions.cs
#   Create: $dev\XUnitOtelExample01\MonitoringFramework\BaseTraceTestAttribute.cs
#   Create: $dev\XUnitOtelExample01\MonitoringFramework\TestRunSpanProcessor.cs
#   Create: $dev\XUnitOtelExample01\MonitoringFramework\TracePerTestAttribute.cs
#   Create: $dev\XUnitOtelExample01\MonitoringFramework\TracePerTestRunAttribute.cs
#   Create: $dev\XUnitOtelExample01\README.md
#   Create: $dev\XUnitOtelExample01\XUnitOtelExample.csproj
#   Create: $dev\XUnitOtelExample01\xunit.runner.json

Install:

❯ dotnet new xunit-otel -o $dev/XUnitOtelExample01 -n XUnitOtelExample

Run tests:

❯ cd $dev/XUnitOtelExample01
❯ dotnet test
# Restore complete (0.4s)
# You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
#   XUnitOtelExample succeeded (0.3s) → bin\Debug\net8.0\XUnitOtelExample.dll
#   XUnitOtelExample test failed with errors (3.3s)
#     C:\Program Files\dotnet\sdk\9.0.100-preview.2.24157.14\Microsoft.TestPlatform.targets(46,5): error : [xUnit.net 00:00:01.77]     XUnitOtelExample.ExampleTests.WaitRandomTime_Fail [FAIL] [$devXUnitOtelExample01\XUnitOtelExample.csproj]
#     $devXUnitOtelExample01\ExampleTests.cs(51): error VSTEST1: XUnitOtelExample.ExampleTests.<>c.<WaitRandomTime_Fail>b__3_0() Assert.True() Failure [$devXUnitOtelExample01\XUnitOtelExample.csproj]
# $devXUnitOtelExample01\ExampleTests.cs(51): error VSTEST1: Expected: True [$devXUnitOtelExample01\XUnitOtelExample.csproj]
# $devXUnitOtelExample01\ExampleTests.cs(51): error VSTEST1: Actual:   False [$devXUnitOtelExample01\XUnitOtelExample.csproj]

# Build failed with errors in 4.4s
# Test run failed. Total: 3 Failed: 1 Passed: 2 Skipped: 0, Duration: 3.3s

See traces:

Navigate to http://localhost:18888/traces.

Results

Initial trace with warmup trace included:

alt

See the details of test run:

alt

Now let's change one of the tests so we can see how failed tests are displayed:

alt

And the details of the test run:

alt

💡 As you can see, the exception is recorded as Trace Event.

Also, we can see the metrics for overall test runs. These metrics shows of execution time per-test and per-class based on tags.

alt

  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 228 6/12/2024
0.1.0 101 6/11/2024