简体   繁体   中英

How to run mspec with resharper runner in STAThread mode

I just updated to Visual Studio 2013, ReSharper 8.0.2 and mspec to the latest version.

It was working fine running all the unit tests that some of the tests are creating UI controls that needs to be STAThread. Don't ask me why some of the tests are like that and can it not be separated. I wish if it was not too late for the game. I don't know what could cause for the Threads to be MTA this time when I updated.

I can easily quick fix this issue to pass the tests by putting a check on EACH call if it is STA and if not just do nothing, but that doesn't work some of the tests required the thread to be STA. I also tried adding [STAThread] on the method called but still no lack.

MSpec said they don't have a similar attribute like NUnit [RequiresSTA]. I am not sure if it was MSpec or ReSharpers thread that caused this to become MTA.

EDIT: Similar but the answer did not solve the problem

Why do I get an Invalid Operation Exception (non STA thread?) running this MSpec test on TeamCity?

EDIT 2: Isolated the problem using the updated mspec libs and run the Unit Test in VS 2012, it works fine and the ApartmentState of the Thread is STAThread . So I'm now concluding it has something to do with ReSharper 8.x having its threadpool start threads in MTA . Anyone know how to config the ApartmentState?

This is as designed by MSpec and it was because ReSharper's Runner that changed.

More info can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM