Mark Needham

Thoughts on Software Development

xUnit.NET: Running tests written in Visual Studio 2010

with 3 comments

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

Written by Mark Needham

May 30th, 2009 at 11:51 am

Posted in .NET

Tagged with

3 Responses to 'xUnit.NET: Running tests written in Visual Studio 2010'

Subscribe to comments with RSS or TrackBack to 'xUnit.NET: Running tests written in Visual Studio 2010'.

  1. xUnit.NET: Running tests written in Visual Studio 2010 – Mark Needham…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

    DotNetShoutout

    1 Jun 09 at 5:03 am

  2. Thanks, that took away that first error. But now I'm stuck with this error:

    An attempt was made to load a program with an incorrect format.

    It refers to the assembly with my tests.

    PS. According to the docs you link to, you shouldn't use requiredRuntime, but supportedRuntime.

    Mike

    23 Sep 09 at 4:17 am

  3. [...] running xunit.test in Visual Studio 2010 for more information.(Note that the currently latest version of .NET 4 runtime is [...]

Leave a Reply