Skip to content

OBPIH-7158 Bump up unit tests coverage (0.9.4 test cycle)#5217

Merged
awalkowiak merged 4 commits intodevelopfrom
OBPIH-7158
Apr 23, 2025
Merged

OBPIH-7158 Bump up unit tests coverage (0.9.4 test cycle)#5217
awalkowiak merged 4 commits intodevelopfrom
OBPIH-7158

Conversation

@alannadolny
Copy link
Collaborator

I am pushing my current version of unit tests because I don't have more available time to add a few more

@codecov
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 8.34%. Comparing base (f02bf36) to head (0bbfb22).
Report is 158 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##             develop   #5217      +/-   ##
============================================
+ Coverage       8.19%   8.34%   +0.15%     
- Complexity       950     976      +26     
============================================
  Files            638     638              
  Lines          43214   43214              
  Branches       10503   10503              
============================================
+ Hits            3542    3608      +66     
+ Misses         39130   39051      -79     
- Partials         542     555      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@ewaterman ewaterman left a comment

Choose a reason for hiding this comment

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

nice work writing tests! 👍

given:
Set<CycleCountItem> cycleCountItems = new TreeSet<>()
for (int countIndex : countIndexes) {
CycleCountItem cycleCountItem = Spy(CycleCountItem)
Copy link
Member

Choose a reason for hiding this comment

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

Is the Spy and the TreeSet needed because otherwise the items are non-unique because they all have id==null?

If you wanted to avoid needing to mock/stub out the CycleCountItem so that you can test with real methods, you can do:

CycleCountItem item = new CycleCountItem(
        countIndex: 1,
        location: bin1,
        status: CycleCountItemStatus.APPROVED
)
item.id = 1
CycleCount cycleCount = CycleCount cycleCount = new CycleCount(
        cycleCountItems: [item]
)

Kind of weird to have to set the id manually, but that's the best solution that I've found

void 'compareTo should return items in order starting with expiration date and location name'() {
given:
mockDomain(InventoryItem)
mockDomain(Location)
Copy link
Member

Choose a reason for hiding this comment

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

you can do mockDomains(InventoryItem, Location). But do you even need to mock the domains? I usually don't need to unless I call .save() on the domain

cycleCountItem2.location.name = 'A'
cycleCountItem3.location.name = 'B'
cycleCountItem4.location.name = 'C'
cycleCountItem5.location.name = 'C'
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but I find it clearer to declare the fields in the constructor:

CycleCountItem cycleCountItem1 = new CycleCountItem(
        inventoryItem: new InventoryItem(
            expirationDate: new Date(2025, 03, 02),
        ),
        location: new Location(
            name: 'A',
        ),
)
...

cycleCountItems.forEach { println(it.hashCode()) }
println("====")
cycleCountItems.sort()
cycleCountItems.forEach { println(it.hashCode()) }
Copy link
Member

Choose a reason for hiding this comment

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

old print statements?

Copy link
Member

Choose a reason for hiding this comment

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

also can't you do?

List<CycleCountItem> cycleCountItems = [cycleCountItem5, cycleCountItem4, cycleCountItem3, cycleCountItem2, cycleCountItem1];

CycleCountRequestCommand cycleCountRequestCommand = new CycleCountRequestCommand(
product: Spy(Product) {
getProductCode() >> PRODUCT_CODE
},
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 instead of new Product(productCode: PRODUCT_CODE)?

}

when: "the command is invalid"
cycleCountRequestBatchCommand.validate()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think asserts like this register under a "when" block. Also shouldn't it be false since it fails validation? You'd want:

...

then:
assert !cycleCountRequestBatchCommand.validate()

when:
controller.createRequests(cycleCountRequestBatchCommand)

then:
thrown(ValidationException)

(I like to explicitly declare my asserts with "assert" in tests.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't treat this as an assertion - after calling the validate, the errors are assigned to CycleCountRequestCommand, so that the errors are thrown in createRequests

cycleCountItem.countIndex = countIndex
cycleCountItems.add(cycleCountItem)
}
CycleCount cycleCount = Spy(CycleCount)
Copy link
Member

Choose a reason for hiding this comment

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

if you're not using Spy anymore in the above test, probably should be consistent and not use it here either

@awalkowiak awalkowiak merged commit cdb24fb into develop Apr 23, 2025
9 checks passed
@awalkowiak awalkowiak deleted the OBPIH-7158 branch April 23, 2025 07:06
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.

3 participants