-
Notifications
You must be signed in to change notification settings - Fork 311
Tests | Move various unit tests to UnitTests project #3458
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?
Tests | Move various unit tests to UnitTests project #3458
Conversation
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3458 +/- ##
==========================================
- Coverage 66.91% 61.08% -5.83%
==========================================
Files 280 274 -6
Lines 62386 62073 -313
==========================================
- Hits 41745 37920 -3825
- Misses 20641 24153 +3512
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.
Thanks for doing this!
Most tests from FunctionalTests can move to UnitTests. We're trying to set a good example in the UnitTests project for how unit tests should behave without the cruft of the existing project. When adding new tests to this project or moving tests over, please do your best to adhere to [industry best practices]. A big piece of that will be removing all of the brittle reflection.
I do think we could go a bit farther removing reflection from SqlCommandSetTest. A lot of the tests are parameterized with type and property names that could get swapped for direct references.
Thanks @mdaigle - that all makes sense. I'll put new tests there and port over older ones as I touch them. I wasn't sure about fixing that part of the SqlCommandSetTests, but I've changed the visibility of those members from private to internal and removed the reflection. |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
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.
I think we should remove an unnecessary check in SqlCommandSet and the associated test.
@@ -114,7 +114,7 @@ protected override void AfterCleared(SqlCommand owner) | |||
} | |||
|
|||
private string _commandText; | |||
private CommandType _commandType; | |||
internal CommandType _commandType; |
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.
Hmmm - Looking at SqlCommand's CommantType setter (line 738), it never contains a value other than Text or StoredProcedure. Why is SqlCommandText performing the same check (line 108)? I think we can remove the check from SqlCommandSet - at most replace it with a Debug.Assert(). Then we don't need the associated test for SqlCommandSet, and we don't need to expose _commandType here.
Unfortunately, the docs for SqlCommand.CommandType don't declare this API promise, or that setting CommandType can throw. But that's out of scope for these changes.
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.
That's just odd! It looks like the validation was part of the codebase even back to System.Data.SqlClient, #1377 added coverage for it as part of a wider drive and I ported it into the new project by mistake. Thanks for catching that.
I've demoted the validation to a simple assertion, and ditched the test.
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 - and one less test to worry about :)
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Description
This is another PR which is a little smaller than it looks. It locates some of the smaller tests which made heavy use of reflection to access internal SqlClient types, moves them from FunctionalTests to UnitTests, removes the reflection and adds descriptions to the test cases. The steps are visible if reviewed commit-by-commit.
Besides some basic test movements, it also lays the groundwork for expanding the test coverage of SqlBuffer. At the moment, we only have explicit coverage of Guid and SqlGuid. A future PR will cover the other types.
There's a little overlap between this and #3423; I've tried to maintain the same standards as there, and I'll revisit them if #3423 is merged first.
More broadly here, there are around 1200 tests in FunctionalTests. I've assumed that the new UnitTests project is eventually going to contain most of the tests in FunctionalTests, is that correct?
Issues
None.
Testing
All unit tests pass.