If you are going to use MSpec in your next .NET project you could face the following issues:
- Visual Studio won’t be able to execute MSpec specifications. (MSpec has it’s own test engine)
- TFS Build Service is able to run only MSTest.
I found several articles on that problem in search engine. The best solution I found was MSMSpec. I’m very appreciate the work HeartattacK had done since it really helped me!
MSMSpec is a T4 template which creates MSTests based on your MSpec classes. So it provides us ability to run MSpec specs in Visual Studio and in TFS Build Service, calculate Code Coverage and Test Impact using MS tools.
Here’s my approach to get it working:
- I added MSMSpec.tt to the solution items. And added its as a link to each MSpec project.
- I made TestExecutionHelper class internal. It was public initially, so if one MSpec project is referencing another, public TestExecutionHelper will result in a conflict. (since both assemblies are declaring the same class). MSMSpec author suggests another workaround but it doesn’t fit my need since I use shared MSMSpec.tt.
- I added 108 to the suppress warnings list in all MSpec projects. (to suppress “_Setup hides inherited member. Use the new keyword if hiding was intended” warning)
- Finally I fixed Cleanups execution order (Parent class Cleanup should be called after Child class Cleanup):
- //var cleanupInfos = FilterByType<Cleanup>(fieldInfos);
- var cleanupInfos = FilterByType<Cleanup>(fieldInfos).Reverse();
Thant’s it. Hope this helps someone!