Testing WPF UserControls Devices
Is it possible to test my WPF custom elements from NUnit (or similar)? If I create an instance of usercontrol in a unit test like:
// Create an instance of the WPF UserControl
var view = new ChildrenListView();
I am getting the following error:
"The calling thread must be STA, because many UI components require this"
I have a feeling that I am missing something very important here.
+2
source to share
2 answers
This article shows you how to fix this problem: NUnit STA Threads and WPF Testing .
If that doesn't fix it, check out the latest post in this forum: Testing a WPF Application with NUnit
+3
source to share
Use the [STAThread] attribute .
[Test]
[STAThread]
public void TestConstructorDoesNotThrow()
{
Expect(() => new ChildrenListView(), Throws.Nothing);
}
0
source to share