2009-09-16 49 views
2

是否可以從NUnit(或類似的)測試我的WPF UserControls?如果我在一個單元測試創​​建用戶控件的實例,像這樣:單元測試WPF UserControls

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

我得到以下錯誤:

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

我得到我想的東西在這裏非常重要的感覺。

回答

0

使用[STAThread]屬性。

[Test] 
    [STAThread] 
    public void TestConstructorDoesNotThrow() 
    { 
     Expect(() => new ChildrenListView(), Throws.Nothing); 
    }