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

Fix xUnit Theory serialization warnings#3186

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
paulmedynski merged 7 commits intomainfromdev/paul/fix-test-theory-data-warnings
Mar 18, 2025

Conversation

paulmedynski
Copy link
Contributor

@paulmedynskipaulmedynski commentedFeb 28, 2025
edited
Loading

xUnit makes 2 passes over unit tests:

  1. Discover all of the tests, and for Theory tests, enumerate all of the test data.
  2. Run all of the tests, enumerating the test data again.

If the enumeration won't produce the same data in both steps, xUnit emits a warning. We have many test cases whose Theory data doesn't enumerate identically in both passes, for a variety of reasons. These tests will still run correctly, but they won't appear in test runner UIs like Visual Studio. Instead, xUnit collapses them into a single test for these UIs.

The warnings are clutter in the console (where I like to run tests), so xUnit provides a mechanism to disable enumeration completely in the discovery phase. I have updated the offending tests to use the MemberData DisableDiscoveryEnumeration flag. This doesn't affect how the tests run, and it doesn't change how UIs display them (collapsed). All it does is suppress the console warnings.

Further reading here:https://xunit.net/faq/theory-data-stability-in-vs

I also added 4 new targets tobuild.proj to make running the tests easier. The existing test running targets function as before.

Commit notes:

  • Suppressed xUnit discovery data enumeration warnings in Function and Manual test projects.
  • Fixed xUnit test data enumeration warnings specific to .NET Framework (enums in the GAC).
  • Added targets to run Windows and Unix tests.
  • Cleaned up test run command lines for improved maintenance and runtime logging.

<Target Name="RunFunctionalTestsWindows" Condition="'$(IsEnabledWindows)' == 'true'">
<PropertyGroup>
<TestCommand>
$(DotnetPath)dotnet test "@(FunctionalTestsProj)"
Copy link
ContributorAuthor

@paulmedynskipaulmedynskiFeb 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Formatted for readability, and then squished back into a single line since<Exec> treats each line in the Command as a separate command!

--filter "category!=non$(TargetGroup)tests&amp;category!=failing&amp;category!=nonwindowstests"
--logger:"trx;LogFilePrefix=Functional-Windows$(TargetGroup)-$(TestSet)"
</TestCommand>
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Modern dotnet tooling supports String.ReplaceLineEndings(), but we're using the old .NET Framework msbuild.exe tooling to build, so we can't have the nice toys :(

[MemberData(
nameof(CEKEncryptionReversalData)
#if NETFRAMEWORK
// .NET Framework puts system enums in something called the Global
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've left a comment once in each file where we're using DisableDiscoveryEnumeration, to make it clear why we're using that flag.

@@ -505,33 +519,25 @@ public override IEnumerable<Object[]> GetData(MethodInfo testMethod)
}
}

publicclass CEKEncryptionReversalParameters : DataAttribute
publicstatic IEnumerable<object[]> CEKEncryptionReversalData()
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Since xUnit only supports DisableDiscoveryEnumeration on MemberData attributes, I have converted all of the data sources to be compatible with MemberData.

You will see similar changes throughout the tests, where data source classes become methods.

[CEKEncryptionReversalParameters]
[MemberData(
nameof(CEKEncryptionReversalData)
#if NETFRAMEWORK
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

.NET doesn't have a GAC, so these tests will enumerate correctly for those targets. We only need to disable for .NET Framework targets.

@@ -4,6 +4,7 @@

using System;
using System.Runtime.InteropServices;
using System.Threading;
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I don't think this is necessary.

#endif
)]
[MemberData(
nameof(ConstructorTextData)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This adds Text to the mix, which seems to have been missing from the InlineData.

@@ -565,7 +584,20 @@ private void ExecuteAndCheckForError(SqlCommand sqlCmd, bool expectError)
try
{
sqlCmd.ExecuteNonQuery();
Assert.Fail("We should have gotten an error but passed instead.");
StringBuilder builder = new(
Copy link
ContributorAuthor

@paulmedynskipaulmedynskiFeb 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

With broken (now disabled) enumeration, xUnit doesn't include the test data in any failure output, so we need to do it ourselves.

This test fails for me on main as well, so I wanted to see what data set was causing the problem. Turns out to be the Date data set (line 1450).

@@ -1,6 +1,13 @@
{
// Typical Windows SQL Server on the local host via TCP.
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

These comments are breaking our CI "Update config.json" task because PowerShell's ConvertFrom-Json fails But as of PowerShell v6, ConvertFrom-Json handles comments:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-7.5

Are we really using ancient PowerShell 5.1 from 2016? I will have to dig into this further.

- Suppressed xUnit discovery data enumeration warnings in Function and Manual test projects.- Fixed xUnit test data enumeration warnings specific to .NET Framework (enums in the GAC).- Added targets to run Windows and Unix tests.- Cleaned up test run command lines for improved maintenance and runtime logging.
@paulmedynskipaulmedynskiforce-pushed thedev/paul/fix-test-theory-data-warnings branch froma04396b toae09fccCompareMarch 3, 2025 14:19
- Added installation of PowerShell Core (pwsh) as a dotnet global tool  so we can use the ADO task PowerShell@2 in pwsh mode on all agents/images.
- Added installation of PowerShell Core (pwsh) as a dotnet global tool  so we can use the ADO task PowerShell@2 in pwsh mode on all agents/images.
- Removed attempt to install PowerShell Core.  Adding it to the 1ES images instead.
- Trying pwsh (PowerShell Core 7.x) again for config file update job.
- Updating pipeline to use my new Win11 1ES image with pwsh.
@codecovCodecov
Copy link

codecovbot commentedMar 5, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.52%. Comparing base(b875e1d) to head(e928eb1).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main    #3186      +/-   ##==========================================- Coverage   72.79%   72.52%   -0.27%==========================================  Files         285      289       +4       Lines       59156    59543     +387     ==========================================+ Hits        43060    43183     +123- Misses      16096    16360     +264
FlagCoverage Δ
addons92.58% <ø> (ø)
netcore75.08% <ø> (-0.38%)⬇️
netfx71.15% <ø> (+0.01%)⬆️

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.

- Reverting pipeline to use the newly rebuilt ADO-CI-Win11 image.
@paulmedynskipaulmedynski marked this pull request as ready for reviewMarch 14, 2025 14:33
@paulmedynskipaulmedynski requested review fromCopilot anda teamMarch 14, 2025 14:33
@paulmedynskipaulmedynski added this to the7.0-preview1 milestoneMar 14, 2025
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 PR addresses xUnit Theory serialization warnings by replacing InlineData and ClassData attributes with MemberData attributes that disable discovery enumeration on .NET Framework. It also refactors several test data providers across multiple test files and updates pipeline configuration steps to use pwsh consistently.

  • Migrate test data attributes from InlineData/ClassData to MemberData with DisableDiscoveryEnumeration for improved xUnit behavior.
  • Refactor test data providers into static methods returning IEnumerable<object[]>.
  • Update pipeline YAML steps to use "pwsh" instead of "powershell" for configuration consistency.

Reviewed Changes

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

Show a summary per file
FileDescription
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.csRefactored xUnit test attributes for Constructor3, Constructor6, and Constructor7 tests using MemberData.
src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ConversionTests.csReplaced ClassData with MemberData in multiple tests to suppress discovery warnings and enhanced error logging details.
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandSetTest.csIntroduced MemberData for CommandType tests with appropriate disable flags on .NET Framework.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTestWithTdsServer.csUpdated MemberData usage to disable discovery enumeration for connection tests on different platforms.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.csConverted JsonBulkCopyTestData from a class to a static method and updated test attributes accordingly.
src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.csReplaced custom data attribute with MemberData for CEK encryption reversal and valid certificate paths tests.
src/Microsoft.Data.SqlClient/tests/FunctionalTests/AmbientTransactionFailureTest.csUpdated MemberData for exception test data to disable discovery enumeration.
src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.csRefactored multiple tests to use MemberData for connection string providers with disable discovery flags.
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.csUpdated FactoryMethodTest to use MemberData with disable discovery enumeration for improved stability.
src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/DatabaseHelper.csConsolidated AE connection string providers into a static DataHelpers class with static test data methods.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.csUpdated MemberData attributes for various DataReader stream tests with disable discovery flags on .NET Framework.
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.csRefactored test data providers for UDT and XXX value tests from ClassData to MemberData.
eng/pipelines/common/templates/steps/update-config-file-step.ymlReplaced "powershell:" with "pwsh:" in the YAML steps for updating the config file.
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlMetaDataTest.csRefactored several tests to use MemberData with DisableDiscoveryEnumeration, and added new static test data providers for constructor tests.
Comments suppressed due to low confidence (2)

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs:27

  • The parameter 'enableStraming' appears to be a typo. It is recommended to rename it to 'enableStreaming' for clarity and consistency.
public void TestJsonBulkCopy(CommandBehavior cb, bool enableStraming, int jsonArrayElements, int rows)

eng/pipelines/common/templates/steps/update-config-file-step.yml:129

  • [nitpick] The task key has been updated from 'powershell:' to 'pwsh:'. Please ensure that all related pipeline configuration files consistently use 'pwsh' as the identifier for PowerShell steps.
- pwsh: |

@cheenamalhotracheenamalhotra added Area\TestsIssues that are targeted to tests or test projects Area\EngineeringUse this for issues that are targeted for changes in the 'eng' folder or build systems. labelsMar 18, 2025
// xUnit can't consistently serialize the data for this test, so we
// disable enumeration of the test data to avoid warnings on the
// console.
DisableDiscoveryEnumeration = true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Would a custom serializer help in this case? Not to say we should do it in this PR, just curious if you experimented with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes looked into that, but didn't want to figure out serialization for all of the affected tests as part of this PR. The changes here don't affect how the tests run, and they don't change how they're visualized in IDEs. They just suppress the warnings on the console. I've opened an ADO task to track fixing the serialization itself.

mdaigle reacted with thumbs up emoji
@paulmedynskipaulmedynski merged commitf3ae72a intomainMar 18, 2025
252 checks passed
@paulmedynskipaulmedynski deleted the dev/paul/fix-test-theory-data-warnings branchMarch 18, 2025 19:24
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@mdaiglemdaiglemdaigle approved these changes

@cheenamalhotracheenamalhotracheenamalhotra approved these changes

Assignees
No one assigned
Labels
Area\EngineeringUse this for issues that are targeted for changes in the 'eng' folder or build systems.Area\TestsIssues that are targeted to tests or test projects
Projects
None yet
Milestone
6.1-preview1
Development

Successfully merging this pull request may close these issues.

3 participants
@paulmedynski@mdaigle@cheenamalhotra

[8]ページ先頭

©2009-2025 Movatter.jp