· xunit

xUnit.NET: Running tests written in Visual Studio 2010

I’ve been playing around with F# in Visual Studio 2010 after the Beta 1 release last Wednesday and in particular I’ve been writing some xUnit.NET tests around the twitter application I’ve been working on.

A problem I ran into when attempting to run my tests against 'xunit.console.exe' is that xUnit.NET is linked to run against version 2.0 of the CLR and right now you can’t actually change the 'targetframework' for a project compiled in Visual Studio 2010.

> xunit.console.exe ..\..\TwitterTests\bin\Debug\TwitterTests.dll

System.BadImageFormatException: Could not load file or assembly 'C:\Playbox\FSharpPlayground\Twitter\TwitterTests\bin\Debug\TwitterTests.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'C:\Playbox\FSharpPlayground\Twitter\TwitterTests\bin\Debug\TwitterTests.dll'
   at System.Reflection.AssemblyName.nGetFileInformation(String s)
   at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
   at Xunit.Sdk.Executor..ctor(String assemblyFilename)
   at Xunit.ExecutorWrapper.RethrowWithNoStackTraceLoss(Exception ex)
   at Xunit.ExecutorWrapper.CreateObject(String typeName, Object[] args)
   at Xunit.ExecutorWrapper..ctor(String assemblyFilename, String configFilename, Boolean shadowCopy)
   at Xunit.ConsoleClient.Program.Main(String[] args)

I wasn’t really sure how to fix this but luckily Dave pointed out that the way to do this is to add a 'requiredRunTime' tag in the 'startup' section of the configuration file (xunit.console.exe.config):

<configuration>
...
	<startup>
      <requiredRuntime version="v4.0.20506" safemode="true"/>
	</startup>
...
</configuration>

And all is good:

> xunit.console.exe ..\..\TwitterTests\bin\Debug\TwitterTests.dll

xUnit.net console runner (xunit.dll version 1.4.9.1416)
Test assembly: C:\Playbox\FSharpPlayground\Twitter\TwitterTests\bin\Debug\TwitterTests.dll
........
Total tests: 8, Failures: 0, Skipped: 0, Time: 0.231 seconds
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket