May 25 2007

MBUnit unittest framework

Category: C#fossmo @ 05:10

I have resently switched from NUnit to MBUnit. One problem in MBUnit, when trying to run a test which uses System.Windows.Window object, was that the thread does not run as a STA thread. I got this error message: "The calling thread must be STA, because many UI components require this."

Example:
[Test]
public void Common_CheckIfListReturnsElement()
{
Window window = new Window();
}

It turns out that MbUnit overrides the ApartmentState, setting it to MTA by default. So you do need to specify the ApartmentState in the fixture attribute:

[TestFixture(ApartmentState = ApartmentState.STA)]
Problem solved!

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Comments are closed