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

Add unit and integration tests for ReferenceTableService. #956

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

valens200
Copy link

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

@valens200
Copy link
Author

@sherrif10 @HerbertYiga you can review this pull request and suggest changes.

Thank you!

@valens200 valens200 changed the base branch from develop_3x to develop April 23, 2024 05:44
@github-actions github-actions bot added the merge conflict Merge Conflicts label May 8, 2024
Copy link

github-actions bot commented May 8, 2024

👋 Hi, @valens200,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

Copy link
Contributor

@CalebSLane CalebSLane left a 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());
Copy link
Contributor

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());
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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.

@valens200
Copy link
Author

Thank you @CalebSLane , I will take a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge conflict Merge Conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants