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

Decouple Dependencies to Improve Testability and Reduce Tight Coupling #3

Open
UnnikrishnanBhargavakurup opened this issue Dec 13, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@UnnikrishnanBhargavakurup
Copy link
Collaborator

Dependencies need to be decoupled. Since most of our dependencies are not injected through constructors, the code has tight coupling and is not testable. We can adopt a hybrid approach: if the dependency is not provided through the constructor, create it using a private factory method. This way, we can avoid bloated constructors while achieving highly testable code.

@UnnikrishnanBhargavakurup UnnikrishnanBhargavakurup added the enhancement New feature or request label Dec 13, 2024
@UnnikrishnanBhargavakurup
Copy link
Collaborator Author

Unit tests should not directly depend on an object. Instead, we should mock all the dependencies to avoid relying on concrete objects. If one of our dependencies requires additional parameter or stops supporting a specific value in the future, we don’t want to rewrite all the tests where we used a real instance instead of a mock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant