Skip to content

OBPIH-6547 Bump-up unit tests coverage#4769

Merged
awalkowiak merged 4 commits intodevelopfrom
OBPIH-6547
Jul 29, 2024
Merged

OBPIH-6547 Bump-up unit tests coverage#4769
awalkowiak merged 4 commits intodevelopfrom
OBPIH-6547

Conversation

@alannadolny
Copy link
Collaborator

No description provided.


and:
Picklist.metaClass.static.findByRequisition = { Requisition foundRequisition -> return new Picklist(requisition: foundRequisition)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd either move the '}' to the above line or move the return statement down to its own line. Same comment for the next test.

It's weird that grails and gorm doesn't really provide a method of stubbing domain methods. This feels weird to have to do but I couldn't find a better solution from googling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd either move the '}' to the above line or move the return statement down to its own line. Same comment for the next test.

I did it like that before and the run autoformatting in Intellij 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that grails and gorm doesn't really provide a method of stubbing domain methods.

There are. We just need to do some more work on testing to start using them. I'm hoping a test-a-thon exercise will help us uncover more testing best practices.

}

void setup() {
inventoryService = Spy(InventoryService) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why Spy? Does it not still work if you make it a Stub? From what I see in the docs, we should generally avoid using Spy if at all possible. https://grails.org/blog/2018-06-22.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line:

1 * inventoryService.generateTransactionNumber()

doesn't work when I change it to Stub, but I think this one check doesn't make too much sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I thought you could still do that with Stub. My bad.

But yes maybe we don't need to care if that internal method call is being made. IMO tests should only care about the inputs and return values of the method that they're testing. The internals should be a black box (which also makes refactoring easier since we're not making assumptions about the internal code, which may change).

then:
'Copy of ' + jsonOfOriginalRequisition['name'] == jsonOfCopiedRequisition['name']
jsonOfOriginalRequisition.remove('name')
jsonOfCopiedRequisition.remove('name')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda weird but I can't think of a better solution off the top of my head outside of just asserting on each key of the map.

quantity | quantityCanceled
10 | 11
20 | 20
21 | 50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about quantityCancelled null and 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing null with value doesn't throw an exception, I can add this case in the test above

quantityCanceled | quantity | modificationItem | substitutionItem | requisitionItems || isCanceled
3 | 3 | null | null | null || true
3 | 2 | null | null | null || false
3 | 2 | Mock(RequisitionItem) | null | null || false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't quantity for these lines be 3? Otherwise they wouldn't be cancelled regardless.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or I guess a better question is do we also want to add lines where quantity is 3 for each of these combos and assert that isCanceled is true

Integer calculatedQuantityNotCanceled = domain.quantityNotCanceled()

then:
calculatedQuantityNotCanceled == quantityNotCanceled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have simple one line asserts like this you can do:

expect:
domain.quantityNotCanceled() == quantityNotCanceled


where:
quantityCanceled | substitutionItem || isSubstituted
0 | null || false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably also worth having a line where quantityCancelled is > 0 but isSubstituted is still false if there are no substitutionItem

RequisitionStatus.PICKING | 0 || true
RequisitionStatus.ISSUED | 0 || true
RequisitionStatus.VERIFYING | null || false
RequisitionStatus.PICKING | null || false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be nice to add some test cases around the modificationItem being set since I see that's used in the isCanceledDuringPick() method. Maybe something similar to what you did for the last test you have in this file. Up to you though.

@ewaterman
Copy link
Member

Nice job with theses tests! 🚀 🚀 🚀

@alannadolny alannadolny changed the base branch from release/0.9.2 to develop July 26, 2024 09:37
@alannadolny alannadolny requested a review from ewaterman July 26, 2024 09:38
@awalkowiak awalkowiak merged commit 8b82725 into develop Jul 29, 2024
@awalkowiak awalkowiak deleted the OBPIH-6547 branch July 29, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants