A handler is a piece of code that responds to something happening — like a message arriving, a request being made, or an event being triggered.
Think of it like a receptionist at an office:
Think of it like a receptionist at an office:
- Someone walks in (an event or message).
- The receptionist (the handler) decides what to do — maybe call someone, give directions, or log the visit.
When something happens — for example, a user clicks a button, a message arrives, or a request comes to a web server — the system passes that “event” to the right handler, which knows what to do next.
In software, a handler does the same:
- It receives input (like an API request or a message from a queue).
- It processes that input — maybe by saving data, calling another service, or sending a response.
As a tester, you might encounter handlers in:
- APIs: A handler processes incoming HTTP requests (e.g., GET or POST).
- Message-based systems (like NServiceBus): A handler processes messages sent between services.
Analogy
Imagine a smart home:
- You press a button (event).
- The system runs a handler that turns on the lights.
As a tester, you’d check:
- Did the lights actually turn on?
- What happens if the button is pressed twice?
- What if the handler fails?
- Event-driven systems: A handler reacts when something happens (e.g., a user signs up)
Understanding handlers helps you:
- Know where the logic lives — so you can test the right thing.
- Understand how data flows throughout the system.
- Spot side effects — like database updates or messages sent.
- Write better unit or integration tests by targeting the handler’s behaviour.