Merge Request #70: Added unit and integration tests for CheckInventory and UpdateInventory using Mocha, Chai, and Chai-HTTP.
Sprint-3 marked the final stage of our project, and my main task was implementing unit and integration tests for the CheckInventory and UpdateInventory endpoints. I had previously written the code for both endpoints, so I was already familiar with how they were supposed to work. That understanding made writing the tests conceptually easy, as I didn’t need to spend time figuring out what the endpoints should do. I knew the expected behaviors and edge cases, which helped guide the testing process and made the test coverage meaningful.
Where I ran into difficulty was not with the logic itself, but with the testing tools specifically, using Mocha, Chai, and Chai-HTTP together. Setting up a testing environment using these tools was trickier than expected. I struggled with managing asynchronous behavior, handling server start/stop during tests, and writing assertions that worked reliably. These challenges weren’t about writing poor logic they were about not being familiar enough with the tools to use them efficiently. That lack of familiarity cost me a lot of time and caused some frustration as I repeatedly debugged problems that had more to do with tool configuration than with the quality of my code.
Looking back, I think one clear improvement for future teams would be to include a basic test template and some documentation in the repository for setting up and using the test tools. Even a single working example using Chai-HTTP would have gone a long way in making the setup easier. That kind of shared resource would reduce the learning curve for everyone and ensure more consistent testing practices across the team.
On a personal level, this sprint reinforced how important it is to practice with tools before relying on them in a real development environment. Even though I knew exactly what needed to be tested, I wasn’t confident with Mocha or Chai. If I had taken the time earlier in the project to experiment with those tools in a small, isolated sandbox, I would have been much more effective during this sprint. That early practice would have prevented many of the delays I encountered and made the testing process smoother and more productive.
The apprenticeship pattern that best fits my experience during this sprint is Practice, Practice, Practice. This pattern emphasizes the importance of repeated, focused practice in low-risk environments. It’s not just about learning something once it’s about practicing it enough that it becomes second nature. That’s exactly what I missed with Mocha and Chai. I hadn’t used them enough beforehand, and it showed. If I had internalized this pattern earlier, I would have taken time before the sprint to build a few quick test cases from scratch, just to become more comfortable with the tools. That effort would have paid off by giving me the fluency to move faster and avoid common mistakes.
Sprint-3 was a good close to the project. It reinforced that understanding the code is only half the challenge being effective also means knowing your tools. With deliberate practice, I could have made this sprint more efficient and less frustrating. That’s a lesson I’ll carry into future projects.
From the blog CS@Worcester – CS Today by Guilherme Salazar Almeida Nazareth and used with permission of the author. All other rights reserved by the author.