Unit testing in WPF .Net 3.0 RRS feed

  • Question

  • Hi,

    Can anyone please tell me that if it is possible to perform unit testing on WPF .Net 3.0 project which has lot of UI elements in it. When I tried to perform unit testing using the NUnit tool, I encountered the following error:

    "TestProject.Class1.TestMethod : System.InvalidOperationException : The calling thread must be STA, because many UI components require this."


    Does anybody knows how to achieve unit test for WPF either by using "NUnit" or "Visual Studio Team System (VSTS)"?



    Thanks in advance,


    Wednesday, April 4, 2007 11:10 AM


All replies

  • Are you getting the same error from Visual Studio also? The blog http://www.hedgate.net/articles/2007/01/08/instantiating-a-wpf-control-from-an-nunit-test may be able to help you regarding nunit problem.
    Thursday, April 5, 2007 8:40 PM
  • Thanks Nagaraju, it worked for me!
    Wednesday, April 11, 2007 5:34 AM

  • you can also have a look at my blog post


    Tuesday, October 23, 2007 9:27 AM
  • Hi,

    Im trying to test a RichTextBox with NUnit. I changed the project to STA and it runs. But it runs very slow, about 8 seconds. Even if I only load a fixture.

    If I create 10 RichTextBoxes, the time difference is minimal, but to start the tests it takes a lot of time.

    Is it normal to be this slow? Is there any trick to speed up these run times?

    Thank you,
    Artur Carvalho
    Wednesday, November 7, 2007 12:55 AM