- Notifications
You must be signed in to change notification settings - Fork311
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
codecovbot commentedJun 2, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown.Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 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
File | Description |
---|---|
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj | Introduces a new project file for unit tests with project property updates. |
src/Microsoft.Data.SqlClient/tests/UnitTests/InternalsVisibleToTest.cs | Adds a simple test using new C# array literal syntax for authentication context. |
netfx and netcore project/ref files | Updates to include InternalsVisibleTo settings and disable reference assembly production. |
src/Microsoft.Data.SqlClient.sln | Adjusts solution composition to incorporate the new unit tests project and updates pipeline references. |
eng/pipelines/common/templates/steps/*.yml | Modifies pipeline steps to run unit tests alongside functional tests. |
build.proj | Adds 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>
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.
Looks great overall, just a few comments/questions.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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.
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.
Uh oh!
There was an error while loading.Please reload this page.
eng/pipelines/common/templates/steps/build-and-run-tests-netcore-step.yml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csprojShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
Looks much better now, thanks!
Uh oh!
There was an error while loading.Please reload this page.
src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
eng/pipelines/common/templates/steps/build-and-run-tests-netcore-step.yml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
564c093
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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 the
InternalsVisibleTo
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:
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:
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: