views:

296

answers:

1

I'm looking for a test framework that helps me test XAML views/controls. Not just to verify correct data binding but especially to test the appearance and behavior of more complex controls. Obviously this will usually result in manual tests.

What I have in mind would look something like this:

  1. Write a normal unit test using whatever unit testing framework you use.
  2. Mock a view model with test data.
  3. Create/Specify the control and supply the view model and needed resources.
  4. (Optional) Define a set of manual assertions.

When executing this test you should be presented with any assertions given (probably as checkboxes with an accept button) and the control in question. Maybe in a container or an extra window (especially if you are testing a Window control).

I think this would be quite handy when developing the control (you supply some test data and can check the control without the whole application) or for parts of the system test to verify the visual style and behavior. With a specialized runner it should also be possible to aggregate the assertion results and create a more comprehensive test report.

I've implemented a very primitive runner but I feel it could be a lot better. Example test (which looks like this):

public void BasicStyle() {
    var runner = new GuiTestRunner(TestContext);
    runner.AddResources(new Uri("pack://application:,,,/Assembly;component/Resources/RadialContextMenuResources.xaml"));

    var contextMenu = ...;
    runner.Container.ContextMenu = contextMenu;

    runner.Assert("Shows a radial context menu with 7 entries.");
    runner.Assert("Each entry has a hover animation.");
    runner.Assert("Each entry can be clicked.");
    runner.Run();
}
+1  A: 

Have you looked at UI automation? Google "wpf ui automation" for sample code that is easier to digest and then head to msdn.

Klerk