Replies: 1 comment 1 reply
-
Express is using a test file structure which is a mixture of Mirroring the file tree and splitting tests up into Features. It's not better in any particular way, just a stylistic choice and what this package has used for a long time. The tests aim to test specific functions, but also specific scenarios. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have a code base of around thousands of line without unit testing. That code has multiple files including schemas, handlers, services, helpers and so on.
I need to introduce unit testing to that code base and exploring multiple file structures used in the community for organizing test cases. I am considering following approaches:
first approach, mirror of code base:
project-root/
├── src/
│ ├── handlers/
│ │ ├── handler1.js
│ │ ├── handler2.js
│ │ └── ...
│ ├── services/
│ │ ├── service1.js
│ │ ├── service2.js
│ │ └── ...
│ ├── middlewares/
│ │ ├── middleware1.js
│ │ ├── middleware2.js
│ │ └── ...
│ └── utils/
│ ├── util1.js
│ ├── util2.js
│ └── ...
├── tests/
│ ├── unit/
│ │ ├── handlers/
│ │ │ ├── handler1.test.js
│ │ │ └── handler2.test.js
│ │ ├── services/
│ │ │ ├── service1.test.js
│ │ │ └── service2.test.js
│ │ ├── middlewares/
│ │ │ ├── middleware1.test.js
│ │ │ └── middleware2.test.js
│ │ └── utils/
│ │ ├── util1.test.js
│ │ └── util2.test.js
│ ├── integration/
│ │ ├── integration1.test.js
│ │ └── integration2.test.js
│ └── e2e/
│ ├── e2e1.test.js
│ └── e2e2.test.js
├── app.js
├── package.json
└── ...
second approach: feature wise unit testing
project-root/
├── src/
│ ├── handlers/
│ │ ├── handler1.js
│ │ ├── handler2.js
│ │ └── ...
│ ├── services/
│ │ ├── service1.js
│ │ ├── service2.js
│ │ └── ...
│ ├── middlewares/
│ │ ├── middleware1.js
│ │ ├── middleware2.js
│ │ └── ...
│ └── utils/
│ ├── util1.js
│ ├── util2.js
│ └── ...
├── tests/
│ ├── login/
│ │ ├── loginHandler.test.js
│ │ ├── loginService.test.js
│ │ └── loginUtils.test.js
│ ├── registration/
│ │ ├── registrationHandler.test.js
│ │ ├── registrationService.test.js
│ │ └── registrationUtils.test.js
│ ├── common/
│ │ ├── commonUtils.test.js
│ │ └── ...
│ └── ...
├── app.js
├── package.json
└── ...
but here in express I see each SUT (system under test/funtion) in the core code is distributed in different files along with it's test cases , that's pretty new approach to me. What could be the potential pros of doing that? 1 reason I can think of is smaller the better approach. Happy to learn more. Thanks
Beta Was this translation helpful? Give feedback.
All reactions