Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 11, 2025

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:

  • HostOptionsTests.cs: 5 tests (reduced from 13) - consolidated individual property tests into comprehensive tests
  • ConsoleLifetimeOptionsTests.cs: 1 test (reduced from 4) - consolidated into single toggle test
  • HostApplicationBuilderSettingsTests.cs: 4 tests (reduced from 10) - removed redundant individual property tests
  • BackgroundServiceExceptionBehaviorTests.cs: 2 tests (reduced from 5) - combined enum value tests, removed unnecessary checks
  • Internal/HostingEnvironmentTests.cs: 5 tests (reduced from 11) - removed redundant individual property tests

Microsoft.Extensions.Hosting.Abstractions Tests (30 tests, reduced from 40)

Created new test project with comprehensive coverage:

  • HostBuilderContextTests.cs: 7 tests - uses AssertExtensions.Throws with parameter name validation
  • HostDefaultsTests.cs: 1 test (reduced from 6) - consolidated key constants into single test
  • EnvironmentsTests.cs: 1 test (reduced from 6) - consolidated environment constants into single test
  • HostEnvironmentEnvExtensionsTests.cs: 16 tests - comprehensive coverage of extension methods

Test Results

51 total tests (previously 79, consolidated based on feedback)

  • Microsoft.Extensions.Hosting.Unit.Tests: 274 tests (reduced from 295)
  • Microsoft.Extensions.Hosting.Abstractions.Tests: 30 tests (reduced from 40)

All tests passing: 304/304 tests pass with 0 failures
Coverage maintained: 87.69% line coverage

Improvements from Feedback

  • Consolidated redundant "HasExpectedValue" tests into single tests with multiple asserts
  • Removed unnecessary validation tests (AreDistinct, AreNotNull, AreNotEmpty)
  • Removed individual property setter tests when comprehensive "AllProperties" or "CanBeToggled" tests existed
  • Used AssertExtensions.Throws to validate exception parameter names
  • Eliminated "CanAssignToVariable" test which provided no value
Original prompt

This section details on the original issue you should resolve

<issue_title>Add more unit tests for Microsoft.Extensions.Hosting*</issue_title>
<issue_description>We have very few tests for Microsoft.Extensions.Hosting* projects which basically gives us no coverage. We should rectify this by adding more tests </issue_description>

Comments on the Issue (you are @copilot in this section)

@ Tagging subscribers to this area: @eerhardt, @maryamariyan See info in area-owners.md if you want to be subscribed.
Issue Details

We have very few tests for Microsoft.Extensions.Hosting* projects which basically gives us no coverage. We should rectify this by adding more tests

Author: Anipik
Assignees: -
Labels:

area-Extensions-Hosting, untriaged

Milestone: -
@stephentoub > Can you provide a coverage report?

@deeprobin, you can just do dotnet build /t:test /p:Coverage=true in the relevant test directory to create a report.</comment_new>

Fixes #49725


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 11, 2025 18:06
…onBuilderSettings, BackgroundServiceExceptionBehavior, and HostingEnvironment

Co-authored-by: stephentoub <[email protected]>
@Copilot Copilot AI changed the title [WIP] Add more unit tests for Microsoft.Extensions.Hosting Add comprehensive unit tests for Microsoft.Extensions.Hosting projects Oct 11, 2025
Copilot finished work on behalf of stephentoub October 11, 2025 18:16
@Copilot Copilot AI requested a review from stephentoub October 11, 2025 18:16
@stephentoub stephentoub marked this pull request as ready for review October 11, 2025 19:45
@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 19:45
@stephentoub stephentoub added test-enhancement Improvements of test source code area-Extensions-Hosting labels Oct 11, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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

@Copilot Copilot AI requested a review from stephentoub October 11, 2025 20:22
Copilot finished work on behalf of stephentoub October 11, 2025 20:22
Copilot finished work on behalf of stephentoub October 12, 2025 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Extensions-Hosting test-enhancement Improvements of test source code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more unit tests for Microsoft.Extensions.Hosting*

2 participants