-
Notifications
You must be signed in to change notification settings - Fork 7
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 comprehensive unit tests for PIRSensorHelper #312
base: main
Are you sure you want to change the base?
Conversation
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.
The unit tests in PIRSensorHelperTest are well-structured, but the assertion messages can be improved for better clarity. For instance, instead of "Expected isMoving to be true when DigitalInput is high", use "Expected isMoving to be true when PIR sensor detects motion (DigitalInput is high)". This makes the test output more informative. Please update the assertion messages accordingly and push the changes. The rest of the implementation looks great! 👍
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.
Great job!
@BeforeEach | ||
void setUp() { | ||
pirSensorInput = mock(DigitalInput.class); | ||
when(pirSensorInput.isHigh()).thenReturn(true); |
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.
Be sure this line does not cause any undefined behavior in your other tests, I tried a similar thing in my PR and noticed some strange behavior in my tests and ended up removing it. If it doesn't cause any issues feel free to keep.
pirSensorHelper = new PIRSensorHelper(pirSensorInput); | ||
} | ||
|
||
@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.
Maybe you could create one function for the test is moving instead of re-declaring the pirSensorHelper multiple times. It's possible to find a way to combine these functions into one, have the same functionality, and only have a few more lines of code.
|
||
@Test | ||
void testMultipleRemoveEventListenerCalls() { | ||
pirSensorHelper.removeEventListener(); |
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.
For our testing purposes I see why you use only two calls to the event listener, however, on your own time before re-committing the code ensure that 4-5 calls to the event listener causes no undefined behavior, two calls may not be enough to be sure.
@Test | ||
void testInitializationLogsCaptureSystemOut() { | ||
PrintStream originalOut = System.out; | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
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.
Love the use of ByteArrayOutputStream, awesome!
Fixes #309
What was changed:
Why was it changed:
How was it changed: