R – UI and event testing

tdd, unit-testing, user-interface, visual-studio

So I know that unit testing is a must. I get the idea that TDD is the way to go when adding new modules. Even if, in practice, I don't actually do it. A bit like commenting code, really.

The real thing is, I'm struggling to get my head around how to unit-test the UI and more generally objects that generate events: user controls, asynchronous database operations, etc.

So much of my code relates to UI events that I can't quite see how to even start the unit testing.

There must be some primers and starter docs out there? Some hints and tips?

I'm generally working in C# (2.0 and 3.5) but I'm not sure that this is strictly relevant to the question.

Best Solution

the thing to remember is that unit testing is about testing the units of code you write. Your unit tests shouldn't test that clicking a button raises an event, but that the code being executed by that click event does as it's supposed to.

What you're really wanting to do is test the underlying code does what it should so that your UI layers can execute that code with confidence.