views:

107

answers:

1

Is it possible to test my WPF UserControls from NUnit (or similar)? If I create an instance of the usercontrol in a unit test like so:

// Create an instance of the WPF UserControl
var view = new ChildrenListView();

I get the following error:

"The calling thread must be STA, because many UI components require this"

I get the feeling I'm missing something very important here.

+2  A: 

This article shows you how to solve this: NUnit STA Threads & Testing WPF.

If that doesn't fix it, take a look at the last entry in this forum post: Testing a WPF Application using NUnit

Mitch Wheat