Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add unit test project#3380

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mdaigle merged 21 commits intomainfromadd-unit-test-project
Jun 5, 2025
Merged

Add unit test project#3380

mdaigle merged 21 commits intomainfromadd-unit-test-project
Jun 5, 2025

Conversation

mdaigle
Copy link
Contributor

@mdaiglemdaigle commentedMay 27, 2025
edited
Loading

Description

This PR adds a new unit test project to the solution and grants that project access to the driver's internal types. The intention of this project is to hold strict unit tests that do not rely on outside resources (azure/local dbs, AKV, etc.). Tests in the unit test project are run as part of the pipeline, before functional tests.

Access to internal types is achieved using theInternalsVisibleTo assembly directive. Internal types must be included in the reference assembly for the project to compile via MSBuild. Automatic reference assembly generation is disabled to avoid conflicts between the auto generated and manually generated assemblies.

Many tests that currently live in the functional tests project could move to this project. I've left that as a future improvement to keep this change targeted.

Why is this important?

Today, most of our testing of internal types uses reflection, but this is problematic for a number of reasons:

  • reflection is slow, error-prone, not type-safe, not refactor-safe, not discoverable (via IDE references), and increases friction to write tests
  • usage of reflection as standard practice encourages access of truly private members of a class
    We need a better unit test setup where we can quickly and easily write comprehensive unit tests for internal classes.

Why not expose internals to integration tests (a.k.a manual tests)?

We could do this, but integration tests are the best way we have to test the public API of our driver. As much as possible, public API testing shouldn't invoke private/internal functionality to generate testing conditions. Integration tests should be stable even as internals are updated. I'm working towards the following testing methodology:

  • Unit tests
    • lowest level
    • test units of code in isolation
    • fast
    • no external resources
    • access to internal types
  • Integration tests
    • high level
    • test public API surfaces
    • slower
    • can use external resources
    • no access to internal types

Testing

I added one existing internal type to the reference assemblies and added a test to access that type to prove that internals are visible to the unit test project.

Guidelines

Please review the contribution guidelines before submitting a pull request:

@mdaiglemdaigleforce-pushed theadd-unit-test-project branch fromc4a7948 toa929667CompareMay 27, 2025 22:45
@codecovCodecov
Copy link

codecovbot commentedJun 2, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.38%. Comparing base(835bf30) to head(042ee13).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main    #3380      +/-   ##==========================================+ Coverage   64.59%   65.38%   +0.79%==========================================  Files         300      300                Lines       65603    65603              ==========================================+ Hits        42375    42896     +521+ Misses      23228    22707     -521
FlagCoverage Δ
addons92.58% <ø> (ø)
netcore68.60% <ø> (+0.02%)⬆️
netfx66.77% <ø> (+1.11%)⬆️

Flags with carried forward coverage won't be shown.Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mdaiglemdaigle marked this pull request as ready for reviewJune 2, 2025 20:50
@CopilotCopilotAI review requested due to automatic review settingsJune 2, 2025 20:50
@mdaiglemdaigle requested a review froma team as acode ownerJune 2, 2025 20:50
Copy link
Contributor

@CopilotCopilotAI 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 pull request introduces a dedicated UnitTests project along with necessary build and pipeline updates to support running unit tests separately from functional tests. Key changes include:

  • Adding a new UnitTests project and updating project files to reference it.
  • Modifying build.proj to incorporate UnitTests targets for both .NET Core and .NET Framework.
  • Adjusting pipeline YAML files to include tasks for running the new unit tests.

Reviewed Changes

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

Show a summary per file
FileDescription
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csprojIntroduces a new project file for unit tests with project property updates.
src/Microsoft.Data.SqlClient/tests/UnitTests/InternalsVisibleToTest.csAdds a simple test using new C# array literal syntax for authentication context.
netfx and netcore project/ref filesUpdates to include InternalsVisibleTo settings and disable reference assembly production.
src/Microsoft.Data.SqlClient.slnAdjusts solution composition to incorporate the new unit tests project and updates pipeline references.
eng/pipelines/common/templates/steps/*.ymlModifies pipeline steps to run unit tests alongside functional tests.
build.projAdds new MSBuild targets for building and running unit tests on both .NET Core and .NET Framework, and integrates the new unit tests project into overall test execution.
Comments suppressed due to low confidence (2)

build.proj:66

  • [nitpick] The naming of 'UnitTestsProj' alongside 'UnitTests' may lead to ambiguity. Consider renaming 'UnitTestsProj' to a clearer identifier (e.g., 'UnitTestProjects') for consistency.
<UnitTestsProj Include="**/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj" />

build.proj:221

  • [nitpick] The MSBuild targets for running unit tests on Windows and Unix contain duplicated command construction logic. Consider extracting the common parts into a separate property or item to reduce duplication and ease maintenance.
<TestCommand>$(DotnetPath)dotnet test "@(UnitTestsProj)" ...</TestCommand>

Copy link
Contributor

@paulmedynskipaulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks great overall, just a few comments/questions.

paulmedynski
paulmedynski previously approved these changesJun 4, 2025
paulmedynski
paulmedynski previously approved these changesJun 4, 2025
Copy link
Contributor

@benrr101benrr101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry,@mdaigle, but I think we need to try and simplify this before we get it running. This is our chance to start with a blank slate and we should take that opportunity to simplify things and be very intentional about if we need to make it more complicated.

paulmedynski
paulmedynski previously approved these changesJun 4, 2025
benrr101
benrr101 previously approved these changesJun 5, 2025
Copy link
Contributor

@benrr101benrr101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks much better now, thanks!

paulmedynski
paulmedynski previously approved these changesJun 5, 2025
@mdaiglemdaigle merged commit564c093 intomainJun 5, 2025
251 checks passed
@mdaiglemdaigle deleted the add-unit-test-project branchJune 5, 2025 19:13
@paulmedynskipaulmedynski added this to the6.1-preview2 milestoneJun 23, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@edwardnealedwardnealedwardneal left review comments

Copilot code reviewCopilotCopilot left review comments

@benrr101benrr101benrr101 approved these changes

@paulmedynskipaulmedynskipaulmedynski approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
6.1-preview2
Development

Successfully merging this pull request may close these issues.

4 participants
@mdaigle@benrr101@paulmedynski@edwardneal

[8]ページ先頭

©2009-2025 Movatter.jp