Skip to content

[test-improver] Add unit tests for ActivityWrapper and OpenTelemetryEnvironmentVariables #11384

Description

@nohwnd-bot

Goal

Add direct unit test coverage for two zero-coverage helper types in Microsoft.Testing.Extensions.OpenTelemetry that had never been exercised in isolation:

  • ActivityWrapper (adapts System.Diagnostics.Activity onto IPlatformActivity) — only covered indirectly through OpenTelemetryPlatformServiceTests, which never drives the non-W3C id-format fallback, IsRecording, the fluent SetTag return value, RecordException's additional-tags merge, or the non-ambient Dispose() path that restores Activity.Current.
  • OpenTelemetryEnvironmentVariables.IsNullOrWhiteSpace — a hand-rolled character scan (used in place of the banned string.IsNullOrWhiteSpace) that gates every environment-variable read across the extension, but had no direct test.

Approach

  • ActivityWrapperTests.cs: constructs plain Activity instances directly (no listener needed) and asserts against ActivityWrapper's public surface — Hierarchical vs. W3C id-format branch for TraceId/SpanId, IsRecording reflecting Activity.IsAllDataRequested, SetTag mutating the underlying activity and returning this, RecordException merging caller-supplied tags alongside the conventional exception tags, and the non-ambient Dispose() restoring Activity.Current.
  • OpenTelemetryEnvironmentVariablesTests.cs: table-driven (DataRow) tests for null, empty, whitespace-only, and non-whitespace inputs, plus a mixed "leading whitespace then content" case.

Both files follow the existing direct-unit-test conventions already used in this project (e.g. MeasurementWrapperTests.cs, TestingPlatformResourceDetectorTests.cs) — no new test infrastructure needed.

Coverage impact

Suite Before After
Microsoft.Testing.Extensions.UnitTests (net8.0) 1879 total, 0 failed, 37 skipped 1892 total, 0 failed, 37 skipped

Trade-offs

Small, focused, low-maintenance additions — no new abstractions or test infrastructure, and both new files sit alongside their existing sibling test files for the same extension area.

Reproducibility

./build.sh -restore
export PATH="$PWD/.dotnet:$PATH"
dotnet build test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj -c Debug -f net8.0
./artifacts/bin/Microsoft.Testing.Extensions.UnitTests/Debug/net8.0/Microsoft.Testing.Extensions.UnitTests

Test Status

Build succeeded (0 warnings/errors). Full Microsoft.Testing.Extensions.UnitTests net8.0 suite: 1892 total, 0 failed, 37 skipped (no regressions). dotnet format whitespace TestFx.slnx --verify-no-changes --include <new files> clean.


Note

This was originally intended as a pull request, but the git push operation failed.

Original error: The process '/usr/bin/git' failed with exit code 128

Workflow Run: View run details and download bundle artifact

The bundle file is available in the agent artifact in the workflow run linked above.

Create the pull request manually
# Download the artifact from the workflow run
gh run download '35403587027' -n agent -D '/tmp/agent-35403587027'

# Resolve the bundle source ref, fetch it into a temporary ref, then create the local branch
bundle_path='/tmp/agent-35403587027/aw-test-assist-activity-wrapper-and-env-vars-tests.bundle'
temp_ref='refs/bundles/create-pr-test-assist-activity-wrapper-and-env-vars-tests-e874b23e10e7cd3e-fa0aef8c'
target_ref='refs/heads/test-assist/activity-wrapper-and-env-vars-tests-e874b23e10e7cd3e'
bundle_source_ref=$(git bundle list-heads "$bundle_path" | awk '$2 ~ /^refs\/heads\// { print $2 }')
if [ -z "$bundle_source_ref" ]; then
  bundle_source_ref=$(git bundle list-heads "$bundle_path" | awk '$2 == "HEAD" { print $2 }')
fi
if [ "$(printf '%s\n' "$bundle_source_ref" | sed '/^$/d' | wc -l | tr -d ' ')" != "1" ]; then
  echo "Expected exactly one bundle source ref, found: $bundle_source_ref" >&2
  exit 1
fi
git fetch "$bundle_path" "${bundle_source_ref}:${temp_ref}"
git update-ref "$target_ref" "$temp_ref"
git checkout 'test-assist/activity-wrapper-and-env-vars-tests-e874b23e10e7cd3e'
# Ensure the working tree matches the updated branch
git reset --hard
# Remove the temporary bundle ref
git update-ref -d "$temp_ref"

# Push the branch to the target remote
git push 'origin' 'test-assist/activity-wrapper-and-env-vars-tests-e874b23e10e7cd3e'

# Create the pull request
gh pr create --title '[test-improver] Add unit tests for ActivityWrapper and OpenTelemetryEnvironmentVariables' --base 'main' --head 'test-assist/activity-wrapper-and-env-vars-tests-e874b23e10e7cd3e' --repo 'microsoft/testfx'

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • southcentralus0.in.applicationinsights.azure.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "southcentralus0.in.applicationinsights.azure.com"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Test Improver workflow. · copilot · auto · 215.3 AIC · ⌖ 19.4 AIC · ⊞ 16.8K · [◷]( · )
Comment /test-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/test-improver.md@main

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mtp-observabilityMTP OpenTelemetry, telemetry, and logging extensions.needs/triageNeeds triage by a maintainer.type/test-gapMissing or insufficient tests.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions