Exclude picker classes from coverage (untestable OS shell dialogs)#30
Exclude picker classes from coverage (untestable OS shell dialogs)#30Kumara-Krishnan wants to merge 2 commits intomainfrom
Conversation
- Change test project target from net10.0 to net10.0-windows10.0.26100.0 so WinUI implementation files (handlers, models, extensions) compile in tests - Add session-level setup to initialize FileSystemProvider with real WinUI services via FileSystemProvider.Initialize() - Replace mock-based extension method unit tests with WinUI argument guard tests that verify non-WinUI objects throw ArgumentException - Rewrite integration tests to exercise real WinUI adapters through FileSystemProvider: WinUIFolderHandler, WinUIFileHandler, WinUIFile, WinUIFolder, FileExtensions, FolderExtensions, AsIFile/AsIFolder - Remove incorrect WinUI source exclusion from codecoverage.config - Update CI artifact path to net10.0-windows10.0.26100.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
WinUIFileOpenPicker, WinUIFileSavePicker, WinUIFolderPicker and WindowUtil open interactive OS shell dialogs that require a live window handle and user input - they cannot be exercised in an automated test runner regardless of whether the project targets WinUI or not. Add [ExcludeFromCodeCoverage] to all four classes so coverage reflects only the code that is actually testable. Line rate: 72.5% -> 89%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot review the new integration tests for winui. It only tests for argument null and not other cases. Use test specialist agent if you have to write tests |
|
@Kumara-Krishnan I've opened a new pull request, #31, to work on those changes. Once the pull request is ready, I'll request review from you. |
There was a problem hiding this comment.
Pull request overview
Updates Cyclotron’s FileSystemAdapter WinUI coverage/testing approach by excluding interactive picker/window-dependent code from coverage while shifting the test project to a Windows WinUI-capable target so WinUI handlers/extensions can be exercised.
Changes:
- Exclude WinUI picker + window helper classes from code coverage via
[ExcludeFromCodeCoverage]. - Move
Cyclotron.Teststonet10.0-windows10.0.26100.0and add a TestSession initializer to callFileSystemProvider.Initialize(). - Replace/expand FileSystemAdapter unit/integration tests to validate WinUI handlers, WinUI models/extensions, and argument guards; update CI artifact path accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| Cyclotron.Tests/Unit/FileSystemAdapter/FileSystemAdapterTests.cs | Updates singleton service-resolution expectations and adds WinUI argument-guard + constants tests. |
| Cyclotron.Tests/TestHelpers/FileSystemAdapterSetup.cs | Adds session-level initialization of FileSystemProvider for all tests. |
| Cyclotron.Tests/Integration/FileSystemAdapter/FileSystemAdapterIntegrationTests.cs | Reworks integration coverage toward WinUI handler/model/extension behaviors using real WinUI services. |
| Cyclotron.Tests/Cyclotron.Tests.csproj | Targets a Windows-specific TFM to enable WinUI types in tests. |
| Cyclotron.FileSystemAdapter/WinUI/Pickers/WindowUtil.cs | Excludes Win32-window-dependent utility from coverage. |
| Cyclotron.FileSystemAdapter/WinUI/Pickers/WinUIFolderPicker.cs | Excludes interactive folder picker from coverage. |
| Cyclotron.FileSystemAdapter/WinUI/Pickers/WinUIFileSavePicker.cs | Excludes interactive save picker from coverage. |
| Cyclotron.FileSystemAdapter/WinUI/Pickers/WinUIFileOpenPicker.cs | Excludes interactive open picker from coverage. |
| .github/workflows/test.yml | Updates coverage artifact path to match the new test TFM output folder. |
| public class FileSystemAdapterSetup | ||
| { | ||
| [Before(TestSession)] | ||
| public static void InitializeFileSystemProvider() | ||
| { | ||
| FileSystemProvider.Initialize(); | ||
| } |
There was a problem hiding this comment.
This introduces a global TestSession side effect (initializing a process-wide singleton) that other tests now implicitly depend on. To reduce ordering/coupling risks, consider initializing FileSystemProvider in the specific test classes that need it (e.g., in [Before(Test)]) or refactoring FileSystemProvider so it can be safely re-initialized/reset for tests.
| [Test] | ||
| public void GetService_ThrowsInvalidOperationException_WhenServiceProviderIsNull() | ||
| public void GetService_ReturnsService_WhenInitialized() | ||
| { | ||
| var instance = FileSystemProvider.Instance; | ||
|
|
||
| var act = () => instance.GetService<IFileHandler>(); | ||
| var result = instance.GetService<IFileHandler>(); | ||
|
|
||
| act.Should().Throw<InvalidOperationException>(); | ||
| result.Should().NotBeNull(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void GetRequiredService_ThrowsInvalidOperationException_WhenServiceProviderIsNull() | ||
| public void GetRequiredService_ReturnsService_WhenInitialized() | ||
| { | ||
| var instance = FileSystemProvider.Instance; | ||
|
|
||
| var act = () => instance.GetRequiredService<IFileHandler>(); | ||
| var result = instance.GetRequiredService<IFolderHandler>(); | ||
|
|
||
| act.Should().Throw<InvalidOperationException>(); | ||
| result.Should().NotBeNull(); |
There was a problem hiding this comment.
These tests rely on FileSystemProvider having been initialized elsewhere (via the new TestSession setup). To keep the unit test class self-contained and avoid hidden ordering dependencies, initialize the provider explicitly within this test class (or within these specific tests) before accessing FileSystemProvider.Instance.
| [Before(Test)] | ||
| public void Setup() | ||
| public async Task Setup() | ||
| { | ||
| _fixture = new TempFileSystemFixture(); | ||
| _folderHandler = FileSystemProvider.Instance.GetRequiredService<IFolderHandler>(); | ||
| _fileHandler = FileSystemProvider.Instance.GetRequiredService<IFileHandler>(); | ||
| _rootFolder = await _folderHandler.GetFolderFromPathAsync(_fixture.RootPath); |
There was a problem hiding this comment.
Setup() assumes FileSystemProvider.Instance is already initialized by the TestSession hook. If that hook is skipped/misconfigured, failures will be confusing and cascade across the suite. Consider either calling FileSystemProvider.Initialize() here (idempotently) or asserting initialization with a clearer failure message before resolving handlers.
| with: | ||
| name: coverage-report | ||
| path: Cyclotron.Tests/bin/Release/net10.0/TestResults/coverage.cobertura.xml | ||
| path: Cyclotron.Tests/bin/Release/net10.0-windows10.0.26100.0/TestResults/coverage.cobertura.xml |
There was a problem hiding this comment.
The coverage artifact path is hard-coded to a specific TFM folder name. This will break the workflow again if the test TFM changes (or if multi-targeting is introduced). Consider using a glob (e.g., Cyclotron.Tests/bin/Release/**/TestResults/coverage.cobertura.xml) or emitting the actual coverage path from the test step and reusing it for upload.
| <TargetFramework>net10.0-windows10.0.26100.0</TargetFramework> | ||
| <TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion> |
There was a problem hiding this comment.
The PR title suggests the change is limited to excluding picker classes from coverage, but this PR also changes the test target framework to a Windows-specific TFM and adds/rewrites substantial WinUI-focused unit/integration tests. Consider updating the PR title/description to reflect the expanded scope, or splitting the testing/TFM changes into a separate PR to keep review and rollback risk smaller.
No description provided.