Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
menu_book Course Curriculum (Software Testing) expand_more
Software Testing / Test Doubles & Dependencies

dependency injection for testing

Learn dependency injection for testing in Software Testing with a dedicated explanation, a concept-specific example, practical cautions, and a mastery check.

12 min read • Intermediate
software-testing-020.py
python
def send_welcome(user, mailer): mailer.send(user['email'],'Welcome')
class FakeMailer:
    def __init__(self): self.sent=[]
    def send(self,to,subject): self.sent.append((to,subject))
m=FakeMailer(); send_welcome({'email':'a@x.com'},m); assert m.sent==[('a@x.com','Welcome')]
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content