Skip to content

Discover test projects in build pipelines#1693

Draft
angularsen wants to merge 1 commit into
masterfrom
agl-codex/discover-test-projects
Draft

Discover test projects in build pipelines#1693
angularsen wants to merge 1 commit into
masterfrom
agl-codex/discover-test-projects

Conversation

@angularsen

Copy link
Copy Markdown
Owner

Summary

  • Discover *.Tests.csproj files instead of maintaining test project arrays.
  • Evaluate each project's TargetFrameworks/TargetFramework with MSBuild and select only projects supporting the requested runtime.
  • Share the same discovery function between the primary net10.0 test pipeline and the net48 compatibility workflow.
  • Preserve separate test execution and coverage reports per project.

Motivation

PR #1692 added isolated test projects and exposed two independent hardcoded lists that could drift: first the net48 workflow omitted the projects, then the primary coverage pipeline did. Test discovery is an independent build-pipeline improvement and ensures future test projects are included automatically when they follow the existing naming convention and declare the target framework.

Validation

  • Verified discovery returns all four current test projects for both net10.0 and net48.
  • Verified discovery under PowerShell 7 and Windows PowerShell 5.1, which is used by build.bat.
  • dotnet build UnitsNet.slnx --configuration Release --no-restore
  • Start-Tests -SkipCoverage: 46,441 passed, 20 skipped across all four net10.0 test projects.
  • The net48 discovery path selected all four projects and completed the first three locally; the full compatibility run is left to CI because the main net48 suite exceeded the local command window.

Replace duplicated hardcoded test project lists with framework-aware discovery shared by the primary and net48 coverage workflows.
@claude

claude Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review

This is a build-tooling-only change (Build/build-functions.psm1, .github/workflows/net48-compatibility.yml) — no quantity/unit JSON, generated code, or public API changes, so there's nothing to check against the units/quantities criteria and no breaking changes.

What it does well

  • Replaces two independently-maintained hardcoded project lists (the exact drift bug called out in the motivation, from Allow configuring global default quantities #1692) with a single Get-TestProjects discovery function shared by both the primary and net48 pipelines.
  • Adds if ($testProjects.Count -eq 0) { throw ... } guards that didn't exist before — a good defensive addition so a discovery regression fails loudly instead of silently skipping all tests.
  • Sort-Object FullName keeps discovery output deterministic across OS/filesystem enumeration order.
  • Correctly accounts for the Condition="$([MSBuild]::IsOSPlatform('Windows'))" net48 addition in the test csproj files — net48 discovery only works on the Windows runner, which matches where net48-compatibility.yml actually runs (runs-on: windows-latest).

Minor nits (non-blocking)

  • Build/build-functions.psm1:50: @($properties.Properties.TargetFrameworks -split ';') + $properties.Properties.TargetFramework doesn't trim whitespace after splitting. If a future <TargetFrameworks>net10.0; net48</TargetFrameworks> (space after ;) is ever added, -contains 'net48' would silently fail to match due to the leading space. Consider ... | ForEach-Object { $_.Trim() } to make this robust against that formatting variant.
  • Same line: when a project only declares TargetFrameworks (no singular TargetFramework, the common case here), $properties.Properties.TargetFramework is empty/$null and still gets appended to the array. Harmless today since it never matches -Framework, but + @($properties.Properties.TargetFramework) | Where-Object { $_ } would keep the array purely meaningful values.
  • Get-ChildItem -Path $root -Recurse -Filter "*.Tests.csproj" walks the entire repo tree (including .git, Artifacts, bin/obj) on every invocation. Not a correctness issue today with only 4 test projects, but worth keeping in mind if the repo grows — could scope to known source directories or add -Exclude/depth limits later.
  • Each discovered project incurs its own dotnet msbuild -getProperty process spin-up. Fine at this scale (4 projects), but something to watch if the test-project count grows significantly.

Test coverage: Reasonable for a CI script change — author validated manually (discovery returns all 4 projects for both TFMs, PS 7/5.1, full net10 run, partial net48 run) per the PR description. No automated test for Get-TestProjects itself, but that's a normal tradeoff for build tooling and CI will exercise the real path on merge.

Overall: solid, well-scoped DRY fix for the exact problem it says it's solving. No blocking issues found.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96%. Comparing base (670ba36) to head (ed572ed).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #1693    +/-   ##
=======================================
- Coverage      96%     96%    -1%     
=======================================
  Files         455     457     +2     
  Lines       29540   30150   +610     
=======================================
+ Hits        28502   29086   +584     
- Misses       1038    1064    +26     
Flag Coverage Δ
net48 96% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant