Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

Motivation and Context

Unit test coverage for Microsoft.Agents.AI.Anthropic was at 68.7%, below the 85% required threshold. Both AnthropicClientExtensions and AnthropicBetaServiceExtensions had uncovered branches in AsAIAgent methods.

Description

Added 12 new unit tests and improved assertions in existing tests to achieve 100% line and branch coverage for both extension classes.

New tests added (6 per extension class):

  • CreateAIAgent_WithTools_AssignsToolsCorrectly
  • CreateAIAgent_WithExplicitMaxTokens_UsesProvidedValue
  • CreateAIAgent_WithToolsAndInstructions_AssignsBothCorrectly
  • CreateAIAgent_WithEmptyTools_DoesNotAssignTools
  • CreateAIAgent_WithNullInstructions_DoesNotSetInstructions
  • CreateAIAgent_WithWhitespaceInstructions_DoesNotSetInstructions

Improved test assertions:

Tests now verify actual agent state rather than just checking creation succeeded:

// Before: only checked name
Assert.Equal("Test Agent", agent.Name);

// After: validates relevant properties
Assert.Equal("Test Agent", agent.Name);
Assert.Equal("Test instructions", agent.Instructions);
Assert.NotNull(agent.ChatClient);

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.
Original prompt

This section details on the original issue you should resolve

<issue_title>.NET: Improve unit test coverage for Microsoft.Agents.AI.Anthropic</issue_title>
<issue_description>85% is the required level, coverage is currently at 68.7%

Image</issue_description>

<agent_instructions>Please analyze the Cobertura Coverage information related to the Microsoft.Agents.AI.Anthropic and lets improve its coverage on non-covered paths.

Please keep the same patterns used for UnitTests existing into the Microsoft.Agents.AI.Anthropic.UnitTests.

Use our repository guidelines regarding UnitTests code as well as use our existing File approach for the UnitTests generatino, only creating new ones if the file being covered have not being covered yet.

Ensure the coverage only covers non-covered paths without duplicating paths that are already covered.

Ensure all existing tests are working on top of the new added ones. This change should only be focused in UnitTests not changing any functionality.</agent_instructions>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve unit test coverage for Microsoft.Agents.AI.Anthropic .NET: Improve unit test coverage for Microsoft.Agents.AI.Anthropic Jan 22, 2026
Copilot AI requested a review from rogerbarreto January 22, 2026 18:07
…perty

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
@rogerbarreto rogerbarreto marked this pull request as ready for review January 23, 2026 14:46
Copilot AI review requested due to automatic review settings January 23, 2026 14:46
Copy link
Contributor

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 improves unit test coverage for the Microsoft.Agents.AI.Anthropic project, increasing it from 68.7% to 100% line and branch coverage. The changes address uncovered code paths in the AsAIAgent extension methods for both AnthropicClientExtensions and AnthropicBetaServiceExtensions.

Changes:

  • Added 12 new unit tests (6 per extension class) covering previously untested branches in the AsAIAgent methods
  • Improved existing test assertions to verify agent state more thoroughly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs Added 6 new tests covering tools assignment, explicit max tokens, combined tools/instructions, empty tools, null instructions, and whitespace instructions scenarios. Added a CapturingHttpHandler helper class for testing HTTP requests.
dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs Added identical 6 new tests for the Beta service extensions, covering the same scenarios as AnthropicClientExtensions. Added a CapturingHttpHandler helper class for testing HTTP requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Improve unit test coverage for Microsoft.Agents.AI.Anthropic

4 participants