Open TaroSchenker opened 11 months ago
SPIKE RESEARCH RESULTS
Hello Team,
I've spent time researching our best options for testing our Node.js, Express, TypeScript, MongoDB, and Mongoose server project and here's what I've found:
Best Testing Libraries: After comparing several options, I recommend we use Jest as our main testing framework. Jest provides a full-fledged testing solution, with features for unit testing, mocking, assertion, coverage reports and more. It also works well with TypeScript, making it a great fit for our project.
Testing Approaches: It's important that we employ both unit testing and integration testing in our project.
Unit Tests: These tests will cover individual functions or components in isolation. They are useful for catching low-level issues early on and they typically run quickly.
Integration Tests: These tests will cover the interaction between multiple components or layers (like the interaction between our server and MongoDB). They are key in catching issues in how different parts of the system work together.
Mocking vs. Real Databases: For unit testing, we should use mocking to simulate the database. This allows the tests to run quickly and keeps them deterministic. Libraries like jest-mock-extended can help us create mocks for our Mongoose models. For integration tests, using a real MongoDB database will provide the most accurate results. We can use an in-memory MongoDB server like mongodb-memory-server for these tests.
Example Tests: I have put together some example tests demonstrating these principles. You'll find them in our test directory.
To summarize, we'll use Jest as our testing library and will apply a mix of unit testing and integration testing. We'll use mocks for unit tests and a real, in-memory MongoDB server for integration tests. Over the next few days, I'll start integrating these practices into our project and will be available for any questions or guidance needed.
Best, [Your Name]
Description
Problem/Task
We need to ensure the proper functioning and reliability of our StaffService methods. There is one test already written which passes, this can be used as a template for the test.
Goals/Objectives
Write unit tests for all methods in StaffService which only mock the MongoDB call. No unit tests should ever call the actual real DB.
Steps to Reproduce/Requirements
1. Install Jest and the necessary TypeScript testing libraries as discovered in our spike.2. Create a new test file for the StaffService.Labels
Testing
Backend
Jest
Unit Tests
Help Wanted
Assignees
GEORGE
Milestones
Testing Phase
Projects
Backend Development
Estimate
With the findings from the previous research/spike, this task should be a great starting point to implementing our testing suite. Ensure to mock the database for these unit tests. Remember, the goal is to test the logic in our methods, not the actual database.