-
Notifications
You must be signed in to change notification settings - Fork 204
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 unit and integration tests for ReferenceTableService. #956
base: develop
Are you sure you want to change the base?
Conversation
@sherrif10 @HerbertYiga you can review this pull request and suggest changes. Thank you! |
👋 Hi, @valens200, This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there. |
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.
A few comments of things to change. I am not the most familiar with Mockito tests, so I haven't added comments there, but it looks good!
id = referenceTablesService.insert(expected); | ||
|
||
result = referenceTablesService.get(id); | ||
assertEquals(expected.getIsHl7Encoded(),result.getIsHl7Encoded()); |
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.
Could you create a method that does assertEquals for every field except id that we can re-use between tests? Ideally we would like to know that all fields are entered successfully on insert, not just ishl7Encoded
assertEquals(expected.getTableName(), result.getTableName()); | ||
assertEquals(expected.getKeepHistory(), result.getKeepHistory()); | ||
assertEquals(expected.getIsHl7Encoded(), result.getIsHl7Encoded()); | ||
assertEquals(expected.getId(),result.getId()); |
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.
can you move the changes (line 49-51) so that they happen in between the insert and the update, so we can test that the object does get successfully updated?
maybe test
- insert New table
- assert insert success as is
- change values
- call update
- assert update success on result
Then maybe create second method that does all the same steps except for the last one and instead:
- get updated values by id
- assert success on result of get
- assert success that result of get = result of update
This would enable us to see that the result returned by the update is the same as what is saved to what can be fetched from the database
public void getAllForHl7Encoding_shouldGetAllReferenceTablesForHl7Encoding() { | ||
List<ReferenceTables> referenceTablesList = referenceTablesService.getAllReferenceTablesForHl7Encoding(); | ||
assertNotNull(referenceTablesList); | ||
assertTrue(referenceTablesList.size() > 0); |
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.
can you assert that the value is exactly right instead of just >0
if the test misses an entry that it should grab this would still pass
public void getAll_shouldGetAllReferenceTables() { | ||
List<ReferenceTables> referenceTablesList = referenceTablesService.getAllReferenceTables(); | ||
assertNotNull(referenceTablesList); | ||
assertTrue(referenceTablesList.size() > 0); |
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.
can you assert that the value is exactly right instead of just >0
if the test misses an entry that it should grab this would still pass
@Test | ||
public void getTotalTablesCount_shouldGetTotalReferenceTablesCount() { | ||
Integer totalCount = referenceTablesService.getTotalReferenceTablesCount(); | ||
assertNotNull(totalCount); |
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.
can you assert that the totalCount is exactly right instead of just not null? this won't detect a miscount.
Thank you @CalebSLane , I will take a look into this. |
Summary
This pull request introduces unit and integration tests for the ReferenceTables service.
Mockito was used to mock external dependencies when executing unit tests focusing on the service’s functionality. The DAO functionalities are included during integration tests.
Related Issue: Add Unit and integration Tests for ReferenceTableService