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
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
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
[...] running xunit.test in Visual Studio 2010 for more information.(Note that the currently latest version of .NET 4 runtime is [...]
Xunit.net quicker quickstart | Ola Kodar
13 Nov 09 at 5:32 am