-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add comprehensive unit tests for Microsoft.Extensions.Hosting projects #120632
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
…onBuilderSettings, BackgroundServiceExceptionBehavior, and HostingEnvironment Co-authored-by: stephentoub <[email protected]>
Co-authored-by: stephentoub <[email protected]>
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 significantly expands test coverage for the Microsoft.Extensions.Hosting ecosystem by adding 79 comprehensive unit tests across multiple projects that previously had insufficient test coverage.
Key Changes:
- Added 39 new tests to Microsoft.Extensions.Hosting for previously untested classes like HostOptions, ConsoleLifetimeOptions, and HostApplicationBuilderSettings
- Created a new test project for Microsoft.Extensions.Hosting.Abstractions with 40 tests covering core abstractions and extension methods
- Added comprehensive coverage for configuration classes, environment utilities, and internal components
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
Internal/HostingEnvironmentTests.cs |
Tests for HostingEnvironment class covering property setters, defaults, and interface implementations |
HostOptionsTests.cs |
Comprehensive tests for HostOptions including timeout configurations, concurrency settings, and edge cases |
HostApplicationBuilderSettingsTests.cs |
Tests for all configuration properties including Args, Configuration, EnvironmentName, and ContentRootPath |
ConsoleLifetimeOptionsTests.cs |
Tests for ConsoleLifetimeOptions focusing on the SuppressStatusMessages property |
BackgroundServiceExceptionBehaviorTests.cs |
Tests for the BackgroundServiceExceptionBehavior enum values and operations |
Microsoft.Extensions.Hosting.Abstractions.Tests.csproj |
New test project configuration file for the Abstractions library |
HostEnvironmentEnvExtensionsTests.cs |
Tests for extension methods including environment checking with case-insensitivity validation |
HostDefaultsTests.cs |
Tests for configuration key constants ensuring correct values and uniqueness |
HostBuilderContextTests.cs |
Tests for constructor validation, property setters, and shared state management |
EnvironmentsTests.cs |
Tests for environment name constants validating expected values and uniqueness |
...ibraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostApplicationBuilderSettingsTests.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting.Abstractions/tests/EnvironmentsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting.Abstractions/tests/HostBuilderContextTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting.Abstractions/tests/HostDefaultsTests.cs
Show resolved
Hide resolved
...ries/Microsoft.Extensions.Hosting/tests/UnitTests/BackgroundServiceExceptionBehaviorTests.cs
Outdated
Show resolved
Hide resolved
...ries/Microsoft.Extensions.Hosting/tests/UnitTests/BackgroundServiceExceptionBehaviorTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/ConsoleLifetimeOptionsTests.cs
Outdated
Show resolved
Hide resolved
...ibraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostApplicationBuilderSettingsTests.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostOptionsTests.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostingEnvironmentTests.cs
Show resolved
Hide resolved
…ions Co-authored-by: stephentoub <[email protected]>
Summary
Successfully added comprehensive unit tests for Microsoft.Extensions.Hosting projects to improve test coverage.
Changes Made
Microsoft.Extensions.Hosting Tests (21 tests, reduced from 39)
Added test files covering previously untested classes:
Microsoft.Extensions.Hosting.Abstractions Tests (30 tests, reduced from 40)
Created new test project with comprehensive coverage:
Test Results
✅ 51 total tests (previously 79, consolidated based on feedback)
✅ All tests passing: 304/304 tests pass with 0 failures
✅ Coverage maintained: 87.69% line coverage
Improvements from Feedback
Original prompt
Fixes #49725
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.