Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUGGESTION] How about writing E2E Tests (Backend Specific)? #31

Open
Manik2708 opened this issue Jun 11, 2024 · 0 comments
Open

[SUGGESTION] How about writing E2E Tests (Backend Specific)? #31

Manik2708 opened this issue Jun 11, 2024 · 0 comments

Comments

@Manik2708
Copy link

I could see three services in this repository:

  1. A PostgreSQL DB
  2. Redis (Caching and Queue)
  3. Express as a store of APIs

We should move towards writing tests for it! Unit Tests are fast but only test the business logic (they can't test whether the SQL query written is actually correct, a code passing all the unit tests might fail the code in production!) and Integration tests are slow (can become a headache for developers).
Therefore we can move to E2E Tests. These tests are faster than Integration tests and can be extended to test the action of these services!

So the route is simple:

  1. We need to setup testing instances of all the services, as tests should not contact the real instances. docker compose can be a good idea for this.

  2. We need to replace the the actual services with the testing instances when tests are running, that means Dependency Injection.

But there are some problems:

a) Dependency Injection Design Pattern: As far I know, there is no good library available for this in Nodejs. tsyringe is there, but it also uses a global instance of container, hence second point can't be achieved!

b) Docker might make the CI slow!

Solutions:

a) Traditional way of Dependency Injection (in JAVA) is by using Constructors and decorators on controllers but JS is a functional programming, so either we have to migrate to a new OOPs based framework like Nestjs or we might use a hack by just changing the protocol to GraphQL and using the context variable for Dependency Injection.

b) Caching in DockerFile and multi stage builds can fix this.

See this repo: https://github.com/Manik2708/Hi_Server which is implemented in Nestjs with E2E Tests and docker compose in CI.

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

No branches or pull requests

1 participant