[test-improver] Add unit tests for ActivityWrapper and OpenTelemetryEnvironmentVariables
- Dominant language
- C#
- Stars
- 1k
- Forks
- 312
- Avg merge
- 8h 30m
- Merged PRs (30d)
- 469
Description
## 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 ` 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](https://github.com/microsoft/testfx/actions/runs/35403587027)
>
> The bundle file is available in the `agent` artifact in the workflow run linked above.
Create the pull request manually
```sh
# 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:
>
> ```yaml
> network:
> allowed:
> - defaults
> - "southcentralus0.in.applicationinsights.azure.com"
> ```
>
> See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information.
>
>
> 🤖 **Automated content by GitHub Copilot.** Generated by the [Test Improver](https://github.com/microsoft/testfx/actions/runs/35403587027/agentic_workflow) workflow. · copilot · auto · 215.3 AIC · ⌖ 19.4 AIC · ⊞ 16.8K · [◷]( · [◷](https://github.com/search?q=repo%3Amicrosoft%2Ftestfx+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests))
> 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
```
Contributor guide
Research direction
Read the existing MeasurementWrapperTests.cs and TestingPlatformResourceDetectorTests.cs conventions, then review the ActivityWrapper and OpenTelemetryEnvironmentVariables entry points. Run the listed net8.0 build and Microsoft.Testing.Extensions.UnitTests command. Done means both new test files cover the stated branches and the suite reports 1892 tests with no failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- Half a day
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100