-
Notifications
You must be signed in to change notification settings - Fork 971
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
Add code coverage for ToolStripSplitButton #12238
base: main
Are you sure you want to change the base?
Add code coverage for ToolStripSplitButton #12238
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #12238 +/- ##
===================================================
+ Coverage 75.42712% 75.43926% +0.01214%
===================================================
Files 3102 3102
Lines 634244 634472 +228
Branches 46866 46880 +14
===================================================
+ Hits 478392 478641 +249
+ Misses 152434 152417 -17
+ Partials 3418 3414 -4
Flags with carried forward coverage won't be shown. Click here to find out more. |
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripSplitButtonTests.cs
Outdated
Show resolved
Hide resolved
public void ToolStripSplitButton_Ctor_ImageAndNullImage() | ||
{ | ||
using Bitmap image = new(10, 10); | ||
_toolStripSplitButton.Image = image; | ||
_toolStripSplitButton.Image.Should().Be(image); | ||
|
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.
If the target of the test is the constructor, you must ensure that the corresponding constructor is called. From the current test, only the Image property is tested, Other test cases also have this problem.
so this test here should like following,
using Bitmap image1 = new Bitmap(10, 10);
_toolStripSplitButton = new("Test", image);
_toolStripSplitButton.SupportsSpaceKey.Should().BeTrue();
_toolStripSplitButton.Image.Should().Be(image);
int defaultDropDownButtonWidth = _toolStripSplitButton.TestAccessor().Dynamic.DefaultDropDownButtonWidth;
_toolStripSplitButton.DropDownButtonWidth.Should().Be(defaultDropDownButtonWidth);
_toolStripSplitButton = new("Test", image: null);
_toolStripSplitButton.Image = null;
_toolStripSplitButton.Image.Should().BeNull();
_toolStripSplitButton.DropDownButtonWidth.Should().Be(defaultDropDownButtonWidth);
The above example needs to be optimized
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.
If the target of the test is the constructor, you must ensure that the corresponding constructor is called.
This test is testing constructor with 2 arguments, not the default one that you call on line 16 in the test class constructor.
In this case we want to dispose button allocated on line 16 and then initialize that field using constructor that takes 2 arguments
_toolStripSplitButton.Dispose();
_toolStripSplitButton = new("Test", image);
In other tests, that validate properties, we are guaranteed that the default constructor is called before the Fact runs. There is no need to execute it twice in other Facts.
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripSplitButtonTests.cs
Outdated
Show resolved
Hide resolved
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.
LGTM with a little question
public void Dispose() => _toolStripSplitButton.Dispose(); | ||
|
||
public static TheoryData<ToolStripItem?> ToolStripItem_Set_TestData() => new() | ||
{ |
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.
Extra space
{ | ||
using ToolStripSplitButton toolStripSplitButton = new(); | ||
|
||
toolStripSplitButton.Text.Should().BeEmpty(); |
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.
toolStripSplitButton.Text.Should().BeEmpty(); | |
_toolStripSplitButton.Text.Should().BeEmpty(); |
I don't think you have to invoke constructor because we are guaranteed that it is called, we can test properties of our field.
public void ToolStripSplitButton_Ctor_ImageAndNullImage() | ||
{ | ||
using Bitmap image = new(10, 10); | ||
_toolStripSplitButton.Image = image; | ||
_toolStripSplitButton.Image.Should().Be(image); | ||
|
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.
If the target of the test is the constructor, you must ensure that the corresponding constructor is called.
This test is testing constructor with 2 arguments, not the default one that you call on line 16 in the test class constructor.
In this case we want to dispose button allocated on line 16 and then initialize that field using constructor that takes 2 arguments
_toolStripSplitButton.Dispose();
_toolStripSplitButton = new("Test", image);
In other tests, that validate properties, we are guaranteed that the default constructor is called before the Fact runs. There is no need to execute it twice in other Facts.
related #10453
Proposed changes
Add unit tests for ToolStripSplitButton.cs to test its properties & methods & events
Microsoft Reviewers: Open in CodeFlow