I wrote last month about my travails in attempting to unit test an Avalon - I mean, Windows Presentation Foundation - application. I vowed to prevail, and indeed I have. As is often the case, it's pretty easy once you know how. <g/>

The basic idea is to stuff your Avalon content into a Window. (Avalon only lets you create one Application per process, but you can create as many Window instances as you like. So you can do this anew for every test case.) Once your UI is in the Window you can poke and prod it by using UIAutomation or by using Avalon directly.

Be warned that Avalon doesn't seem to have considered that it might be used this way, so you may run into problems here and there. For example, I found that using the RadioButton's GroupName property (which gathers radio buttons into a group wherein only one of them can ever be selected) does not work across multiple threads. I would call these bugs - and you can bet I'm logging them as such! - but the Avalon team may have a different point of view.

Due to its size, I posted the code I use to do this separately. I've used this with the PDC build of Avalon; it may work on previous builds but no guarantees. Please also see the disclaimer in my sidebar.

Enjoy!

 

*** Want a fun job on a great team? I need a tester! Interested? Let's talk: Michael dot J dot Hunter at microsoft dot com. Great coding skills required.