CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE
Why does depending on abstractions (interfaces) rather than concrete classes, as the Dependency Inversion Principle recommends, make unit testing easier?
- A. It makes the code compile faster in every case
- B. It guarantees 100% code coverage automatically
- C. A test can substitute a lightweight mock or fake implementing the same interface, isolating the class under test from the real, possibly slow or unavailable, concrete dependency
- D. It removes the need to write any tests at all
Correct answer: C. A test can substitute a lightweight mock or fake implementing the same interface, isolating the class under test from the real, possibly slow or unavailable, concrete dependency
Coding against an interface lets a test supply an alternative implementation (a mock/fake) satisfying that same interface, so the unit under test can be exercised without invoking the real dependency's actual behaviour.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A deployment strategy routes 100% of production traffic to a brand-new environment all at once, after it has been fully tested in…
- A feature flag (feature toggle) used alongside continuous deployment allows a team to:
- What is the key difference between git merge --no-ff and a fast-forward merge?
- Which rollback characteristic distinguishes blue-green deployment from canary release?
- For a organic mode project with Basic COCOMO effort E = 26.9 person-months, the development time formula is D = 2.5 × E^0.38 months. What…
- What problem does a pipeline stage that runs automated security/dependency vulnerability scanning on every build ('shifting security…