As I’ve been working another blog post about my adventures in learning BDD ala MSpec, I ran into something that I wanted to share as the problem wasn’t immediately obvious (to me anyway).
The problem is that MSpec has a dependency on version 188.8.131.52 of the nunit.framework assembly – and frankly, it’s not really a very big problem. In fact, I didn’t even notice it until now because I had been running all of my specs exclusively through the Resharper runner (enabled by the MSpec plugin).
** As a side note, using R# with the MSpec plugin absolutely rocks, and while the runner is needed for integrating MSpec with your automated builds, I would totally recommend R# for your regular dev rhythm.
In my project, I originally had some integration tests in the same assembly as my specifications. As a result, I had a direct reference to NUnit (version 184.108.40.20622) in addition to the reference to Machine.Specifications and Machine.Specifications.NUnit (which has a reference to version 220.127.116.11). As a result, the later version of NUnit was being copied to my bin folder and throwing a file load exception for every specification when run using the console runner.
My initial reaction was to simply move all my integration tests to a different assembly and remove the direct NUnit reference in my specifications assembly (remember that referencing Machine.Specifications.NUnit will copy the version of NUnit to the bin folder that MSpec expects. No problem – everything works as you would expect.
However, it seems reasonable to me that, at least in larger projects that are wanting to incorporate specs and not have to re-write all existing tests, that it would be good to simply reconfigure the MSpec console runner to use the latest version of NUnit. This can be done easily using the standard .NET assembly binding redirection feature. Simply create a file named Machine.Specifications.ConsoleRunner.exe.config and drop it into the MSpec folder that contains your console runner (Machine.Specifications.ConsoleRunner.exe). The contents of the file should look like this.
<?xml version="1.0"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" /> <bindingRedirect oldVersion="18.104.22.168" newVersion="22.214.171.12422"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Run the MSpec console again, and voila! Works like a charm.