Performance: Why DI makes testing easier
MEDIUM IMPACT
Dependency Injection (DI) affects how easily components can be isolated and tested without loading unnecessary dependencies, improving test execution speed and reliability.
class UserComponent { constructor(userService) { this.userService = userService; } getUser() { return this.userService.fetchUser(); } } // In tests, inject a mock userService instead of real one
class UserComponent { constructor() { this.userService = new UserService(); } getUser() { return this.userService.fetchUser(); } }
| Pattern | Dependency Loading | Test Setup Time | Test Execution Speed | Verdict |
|---|---|---|---|---|
| Direct instantiation inside component | Loads all real dependencies | High | Slow | [X] Bad |
| Dependency Injection with mocks | Loads only mocks | Low | Fast | [OK] Good |