Skip to content

Migrate Get-Package E2E tests to fast cmdlet-level unit tests - #7457

Merged
nkolev92 merged 17 commits into
devfrom
dev-nkolev92-powershellCmdletTests
Jun 9, 2026
Merged

nkolev92 merged 17 commits into
devfrom
dev-nkolev92-powershellCmdletTests

Conversation

@nkolev92

@nkolev92 nkolev92 commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Bug

Progress: https://github.com/NuGet/Client.Engineering/issues/2085

Description

Migrates Get-Package end-to-end PowerShell tests to fast, focused unit tests that invoke GetPackageCommand directly in a test runspace. This replaces the approach in #7452 (Apex migration) with a significantly cheaper and more faithful alternative.

Approach

Instead of many individual Apex E2E tests (which each require a full VS instance), this PR:

  1. Registers GetPackageCommand in an InitialSessionState with a SessionStateCmdletEntry
  2. Creates a Runspace with a custom TestPSHost providing required PrivateData (activePackageSource, CancellationTokenKey)
  3. Mocks VS services via MockedVS + IComponentModel (same pattern as NuGet.PackageManagement.VisualStudio.Test)
  4. Creates real packages on disk with SimpleTestPathContext + SimpleTestPackageUtility
  5. Invokes the cmdlet through a pipeline and asserts on the typed output objects (PowerShellRemotePackage, PowerShellUpdatePackage, PowerShellInstalledPackage)

Benefits over Apex tests

Apex (PR #7452) Unit tests (this PR)
Execution time Minutes (VS startup) ~1 second (all 16 tests)
Infrastructure Full VS instance MockedVS + local packages
Fidelity Parses text output from PMC Asserts on typed cmdlet output
CI cost Heavy, flaky Lightweight, deterministic

Changes

  • 16 cmdlet-level unit tests in NuGetConsole.Host.PowerShell.Test/Cmdlets/GetPackageCommandTests.cs covering:
    • ListAvailable: basic, filter, prerelease filtering, AllVersions, absolute path source
    • Updates: prerelease filtering, AllVersions combinations
    • Installed: list all, per-project, other project empty, filter
  • 1 combined Apex integration test (GetPackage_InstallListAndUpdateLifecycleAsync) that validates the full PMC lifecycle in a single VS session: Install → Get-Package → Get-Package -ListAvailable → Get-Package -Updates -Prerelease
  • Removed 15 individual Apex tests that are now redundant (covered by unit tests)
  • Removed GetPackageViewModelTests.cs (unfaithful unit tests that only tested static view model methods)

Migration mapping from original PS1 tests

PowerShell E2E test New unit test
Test-GetPackageCollapsesPackageVersionsForListAvailable GetPackageListAvailable_WithLocalSource_ReturnsPackagesAsync
Test-GetPackageAcceptsSourceName GetPackageListAvailable_WithFilter_ReturnsMatchingPackageAsync
Test-GetPackageAcceptsAbsolutePathSource, `Test-GetPackageAcceptsRelativePathSource
, Test-GetPackageAcceptsRelativePathSource2` GetPackageListAvailable_WithAbsolutePathSource_ReturnsPackagesAsync - Merged 3 tests into one since they are redundant
Test-ZipPackageLoadsReleaseNotesAttribute GetPackageListAvailable_WithFilter_FindsReleaseNotesPackageAsync
Test-GetPackagesDoesNotShowPrereleasePackagesWhenSwitchIsNotSpecified GetPackageListAvailable_WithoutPrerelease_HidesPrereleaseVersionsAsync
Test-GetPackagesAllVersionsDoesNotShowPrereleasePackagesWhenSwitchIsNotSpecified GetPackageListAvailable_AllVersionsWithoutPrerelease_HidesPrereleaseVersionsAsync
Test-GetPackagesWithPrereleaseSwitchShowsPrereleasePackages GetPackageListAvailable_WithPrerelease_ShowsPrereleaseVersionAsync
Test-GetPackagesWithAllAndPrereleaseSwitchShowsAllPackages GetPackageListAvailable_AllVersionsWithPrerelease_ShowsAllVersionsAsync
Test-GetPackageUpdatesDoNotReturnPrereleasePackagesIfFlagIsNotSpecified GetPackageUpdates_WithoutPrerelease_DoesNotReturnPrereleaseUpdateAsync
Test-GetPackageUpdatesReturnPrereleasePackagesIfFlagIsSpecified GetPackageUpdates_WithPrerelease_ReturnsPrereleaseUpdateAsync
Test-GetPackageUpdatesReturnAllVersionsIfFlagIsSpecified GetPackageUpdates_AllVersionsWithoutPrerelease_ReturnsStableVersionAsync
Test-GetPackageUpdatesReturnAllVersionsAndPrereleaseVersionsIfTwoFlagsAreSpecified GetPackageUpdates_AllVersionsWithPrerelease_ReturnsAllEligibleUpdatesAsync
Test-GetPackageWithUpdatesListsUpdates GetPackageInstalled_ListsInstalledPackagesAsync

PR Checklist

  • Tests added/updated
  • Removed corresponding PS1 tests (follow-up once this approach is validated)

Copilot AI and others added 17 commits June 5, 2026 10:12
- Remove duplicate private static GetConsole method in GetPackageTestCase.cs that hid the inherited protected base member (CS0108) and incorrectly used inaccessible GetComponentModelService<T>() (CS0122).

- Remove unused 'using NuGet.Test.Utility;' from GetPackageTestCase.cs (IDE0005).

- Remove unused 'using System.Linq;' from NuGetConsoleTestCase.cs (IDE0005).

Co-authored-by: Copilot <[email protected]>
…e-duplicates' into dev-nkolev92-powershellCmdletTests
- 16 tests covering ListAvailable, Updates, and Installed scenarios
- Tests invoke GetPackageCommand directly in a PowerShell runspace
- Covers prerelease filtering, version collapsing, project filtering
- Replaces need for expensive Apex E2E tests (PR #7452)

Co-authored-by: Copilot <[email protected]>
…ration test

Consolidate 15 individual Apex tests into one combined test that exercises
the full Get-Package lifecycle: Install → List Installed → ListAvailable → Updates.
Detailed filtering logic (prerelease, AllVersions) is now covered by fast
cmdlet-level unit tests in GetPackageCommandTests.cs.

Co-authored-by: Copilot <[email protected]>
@nkolev92
nkolev92 marked this pull request as ready for review June 8, 2026 16:35
@nkolev92
nkolev92 requested a review from a team as a code owner June 8, 2026 16:35
@nkolev92
nkolev92 requested review from jebriede and zivkan June 8, 2026 16:35
Comment thread test/EndToEnd/tests/GetPackageTest.ps1 Resolved
@nkolev92
nkolev92 requested a review from Nigusu-Allehu June 9, 2026 19:20
@nkolev92
nkolev92 merged commit 35ef8e7 into dev Jun 9, 2026
17 of 18 checks passed
@nkolev92
nkolev92 deleted the dev-nkolev92-powershellCmdletTests branch June 9, 2026 20:13
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.

4 participants