MSpec and TFS Build Service (MSMSpec)

If you are going to use MSpec in your next .NET project you could face the following issues:

  1. Visual Studio won’t be able to execute MSpec specifications. (MSpec has it’s own test engine)
  2. 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:

  1. I added to the solution items. And added its as a link to each MSpec project.
  2. 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
  3. 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)
  4. Finally I fixed Cleanups execution order (Parent class Cleanup should be called after Child class Cleanup):
  1. //var cleanupInfos = FilterByType<Cleanup>(fieldInfos);
  2. var cleanupInfos = FilterByType<Cleanup>(fieldInfos).Reverse();

Thant’s it. Hope this helps someone!