-
Notifications
You must be signed in to change notification settings - Fork 1.1k
.NET: Improve unit test coverage for Microsoft.Agents.AI.Anthropic #3382
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
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
…perty Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
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 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. |
Motivation and Context
Unit test coverage for
Microsoft.Agents.AI.Anthropicwas at 68.7%, below the 85% required threshold. BothAnthropicClientExtensionsandAnthropicBetaServiceExtensionshad uncovered branches inAsAIAgentmethods.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_AssignsToolsCorrectlyCreateAIAgent_WithExplicitMaxTokens_UsesProvidedValueCreateAIAgent_WithToolsAndInstructions_AssignsBothCorrectlyCreateAIAgent_WithEmptyTools_DoesNotAssignToolsCreateAIAgent_WithNullInstructions_DoesNotSetInstructionsCreateAIAgent_WithWhitespaceInstructions_DoesNotSetInstructionsImproved test assertions:
Tests now verify actual agent state rather than just checking creation succeeded:
Contribution Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.