Skip to content
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

Tests should use theory data #11171

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

woefulpines
Copy link

@woefulpines woefulpines commented Apr 6, 2024

Makes progress to fix #11041

Proposed changes

  • Changed untyped test data to use typed TheoryData objects.
  • Allowing us to enable xUnit1024 errors in .editorconfig.
  • Currently fixes test cases in Windows form analyzer (CSharp) with one exception
    for the file reader font converter.

Customer Impact

  • No customer impact, just refactoring old test cases.

Regression?

  • No

Risk

-There should be no risk in moving to strongly typed parameterized test methods.

Test methodology

  • Because the tests are functionally identical, I used the tests that were already present.

Test environment(s)

Microsoft Reviewers: Open in CodeFlow

@woefulpines
Copy link
Author

@dotnet-policy-service agree

@woefulpines
Copy link
Author

For the testing environments, would you like me to paste my dotnet --info or could I remove it?

Copy link

codecov bot commented Apr 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.44649%. Comparing base (d9e9d93) to head (9bed97d).
Report is 120 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #11171         +/-   ##
===================================================
- Coverage   73.44664%   73.44649%   -0.00016%     
===================================================
  Files           3098        3098                 
  Lines         632225      632229          +4     
  Branches       46653       46653                 
===================================================
+ Hits          464348      464350          +2     
- Misses        164485      164487          +2     
  Partials        3392        3392                 
Flag Coverage Δ
Debug 73.44649% <100.00000%> (-0.00016%) ⬇️
integration 18.36830% <ø> (+0.00637%) ⬆️
production 46.91082% <ø> (-0.00071%) ⬇️
test 94.98604% <100.00000%> (+0.00005%) ⬆️
unit 43.87654% <ø> (-0.00107%) ⬇️

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

{
var testData = new TheoryData<OutputKind>();
Copy link
Member

Choose a reason for hiding this comment

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

[nit]

Suggested change
var testData = new TheoryData<OutputKind>();
TheoryData<OutputKind> testData = new();

Copy link
Member

@lonitra lonitra left a comment

Choose a reason for hiding this comment

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

Left a few comments, thanks for helping out in this area!

[MemberData(nameof(TestConvertFormData))]
#pragma warning restore xUnit1042 // The member referenced by the MemberData attribute returns untyped data rows
Copy link
Member

Choose a reason for hiding this comment

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

We typically do not want this comment twice for suppressions

Suggested change
#pragma warning restore xUnit1042 // The member referenced by the MemberData attribute returns untyped data rows
#pragma warning restore xUnit1042

Copy link
Member

Choose a reason for hiding this comment

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

The comment in both locations is automatically added by Roslyn's code fix

Copy link
Member

Choose a reason for hiding this comment

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

Yep, for the most part we've been manually removing the comment on restore when adding these warnings

Comment on lines +58 to +59
testData.Add
(
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
testData.Add
(
testData.Add(

Copy link
Member

Choose a reason for hiding this comment

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

I would have expected this one to be flagged by analyzers

@@ -57,7 +57,9 @@ public static IEnumerable<object[]> TestConvertFormData()
}

[Theory]
#pragma warning disable xUnit1042 // The member referenced by the MemberData attribute returns untyped data rows
Copy link
Member

Choose a reason for hiding this comment

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

What change caused this warning?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for the delay. Disabling the warning addressed the function uses an enum that is marked as internal. So I was not able to put it into a TheoryData<...> object getting a CS0050 error. I thought disabling was the best course of action for this specific test case.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. Thank you for your explanation. I think disabling for this case is fine.

Copy link
Member

Choose a reason for hiding this comment

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

If this is a common situation (it may be), we could implement a DiagnosticSuppressor that automatically suppresses xUnit1042 for these cases.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you all for the help and comments.

@lonitra lonitra added the 📭 waiting-author-feedback The team requires more information from the author label Apr 9, 2024
@@ -113,4 +115,4 @@ public void EmptyStringInput()
Assert.Null(font);
}
}
}
}
Copy link
Member

@sharwell sharwell Apr 9, 2024

Choose a reason for hiding this comment

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

This seems undesirable. I can understand not forcing it to move the other direction to fix a problem, but this is creating a problem where there wasn't one.

@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback The team requires more information from the author label Apr 18, 2024
@lonitra lonitra added the 📭 waiting-author-feedback The team requires more information from the author label Apr 18, 2024
@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback The team requires more information from the author label Apr 20, 2024
@lonitra
Copy link
Member

lonitra commented Apr 25, 2024

@woefulpines could you update PR with feedback addressed so we can take this to completion? Let me know if there are any concerns :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📭 waiting-author-feedback The team requires more information from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests should use TheoryData<>
4 participants