OBPIH-6547 Bump-up unit tests coverage#4769
Conversation
|
|
||
| and: | ||
| Picklist.metaClass.static.findByRequisition = { Requisition foundRequisition -> return new Picklist(requisition: foundRequisition) | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
what about quantityCancelled null and 0?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
shouldn't quantity for these lines be 3? Otherwise they wouldn't be cancelled regardless.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
When you have simple one line asserts like this you can do:
expect:
domain.quantityNotCanceled() == quantityNotCanceled
|
|
||
| where: | ||
| quantityCanceled | substitutionItem || isSubstituted | ||
| 0 | null || false |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
Nice job with theses tests! 🚀 🚀 🚀 |
No description provided.