Unit Testing Events And Callbacks In C#
The Problem When you want to unit test a method it’s usually pretty simple. Call the method, pass it it’s parameters and assert against it’s return value, or some other property of the object that may have changed. What happens when a method doesn’t return a value, or update some property? What happens when it leads (perhaps after some delay) to an event firing, or a callback getting called? Events firing and callbacks getting called are very similar, but subtly different, so I’ll cover them both.