-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Enforce exactly one Category attribute per UI test #33242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Updated NUnitTestMissingCategoryAnalyzer to enforce exactly one category: - MAUI0001: Error when test has no category - MAUI0002: Error when test has multiple categories - Changed severity from Warning to Error - Excludes platform-specific ignore attributes (FailsOn*) from category count - Fixed 314 tests that had multiple categories by keeping the most specific one: - Control-specific categories preferred (Button, Entry, CollectionView, etc.) - Removed generic 'Compatibility' category in favor of specific categories - Tests no longer run multiple times in CI due to category duplication - Added analyzer unit tests (20 tests covering all scenarios): - Missing category detection - Multiple categories detection - Custom CategoryAttribute derivatives - Platform ignore attribute exclusions This change eliminates ~1,256 duplicate test executions per CI run (314 tests × ~1 extra run × 4 platforms).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enforces that every UI test has exactly one [Category] attribute through a build-time analyzer, preventing tests from running multiple times in CI. The analyzer now emits build errors (MAUI0001 for missing categories, MAUI0002 for multiple categories) and excludes platform-specific ignore attributes from the category count.
Key Changes
- Analyzer enhancements: Updated
NUnitTestMissingCategoryAnalyzerto detect and report both missing and multiple categories as build errors - Test fixes: Removed duplicate categories from 314 tests across the codebase
- New test project: Added
UITest.Analyzers.Testswith 20 comprehensive tests validating analyzer behavior - Code fix providers: Updated to reference new diagnostic ID
MissingCategoryDiagnosticId
Reviewed changes
Copilot reviewed 154 out of 154 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
NUnitTestMissingCategoryAnalyzer.cs |
Enhanced analyzer with MAUI0001/MAUI0002 diagnostics, category counting logic, and platform ignore attribute exclusion |
NUnitTestMissingCategoryMethodCodeFixProvider.cs |
Updated to use new MissingCategoryDiagnosticId constant |
NUnitTestMissingCategoryClassCodeFixProvider.cs |
Updated to use new MissingCategoryDiagnosticId constant |
UITest.Analyzers.Tests.csproj |
New xUnit test project for analyzer validation |
NUnitTestCategoryAnalyzerTests.cs |
20 comprehensive tests covering missing/multiple categories, custom attributes, and edge cases |
AnalyzerTestHelpers.cs |
Helper utilities for running analyzer tests with NUnit stubs |
StepperUITests.cs through GraphicsViewFeatureTests.cs |
Removed duplicate [Category] attributes from 314 tests |
Microsoft.Maui-dev.sln |
Added new test project to solution with proper folder structure |
|
@copilot can you fix this D:\a_work\1\s\src\Controls\tests\TestCases.Shared.Tests\Tests\Issues\XFIssue\GitHub1648.cs(20,15): error MAUI0002: Test method 'GitHub1648Test' has 2 |
- [x] Initial plan - [x] Fix GitHub1648Test - removed Compatibility category, kept Navigation - [x] Fix Issue3413Test - removed Compatibility category, kept SearchBar - [x] Verify build passes with analyzer <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Description
This PR enforces that every UI test has exactly one
[Category]attribute through a build-time analyzer. Previously, tests could have multiple categories which caused them to run multiple times in CI.Each test needs to have a category so they are ran in the CI pipeline. With this analyzer we ensure that this is not forgotten during development.
Changes
Analyzer Updates (
NUnitTestMissingCategoryAnalyzer)WarningtoErrorFailsOnAndroidWhenRunningOnXamarinUITest, etc.) from the category count since they conditionally derive fromCategoryAttributeFixed 314 Tests
All tests with multiple categories have been fixed by keeping the most appropriate single category:
Compatibilityin favor of more specific onesAdded Analyzer Unit Tests
New test project
UITest.Analyzers.Testswith 20 tests covering:CategoryAttributederivativesCI Impact
Tests with multiple categories were running multiple times because the CI uses category-based test filtering with OR logic. For example, a test with
[Category("Button")]and[Category("Compatibility")]would run in both the Button job and the Compatibility job.Before this PR:
After this PR:
Testing