Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch Build Fails with XUnit on VS2010
aboy021
#1 Posted : Thursday, April 11, 2013 11:45:21 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/24/2013(UTC)
Posts: 19
Location: New Zealand

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
I have a very simple C# project that contains the following code:

Code:
namespace StringKata
{
	using Xunit;

	public class StringCalculator
	{
		 public int Add(string numbers)
		 {
			 return 0;
		 }
	}

	public class StringCalculatorTests
	{
		[Fact]
		public void Empty_string_is_zero()
		{
			var stringCalculator = new StringCalculator();
			var actual = stringCalculator.Add("");
			Assert.Equal(0, actual);
		}
	}
}


I have included a few nuget packages:

Code:
<packages>
  <package id="AutoFixture" version="3.0.8" targetFramework="net40" />
  <package id="AutoFixture.AutoNSubstitute" version="3.0.8" targetFramework="net40" />
  <package id="AutoFixture.Xunit" version="3.0.8" targetFramework="net40" />
  <package id="NSubstitute" version="1.4.3.0" targetFramework="net40" />
  <package id="xunit" version="1.9.1" targetFramework="net40" />
  <package id="xunit.extensions" version="1.7.0.1540" targetFramework="net40" />
</packages>


I also use ReSharper 7.1 and have installed the xunit contrib plugin for resharper.

But the build fails. I've set the output to verbose and this is what I get:

Quote:

Gallio.Model.ModelException: An exception occurred while invoking a test driver. ---> System.IO.FileNotFoundException: Could not load file or assembly 'xunit, Version=1.9.0.1566, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies. The system cannot find the file specified.
at Gallio.XunitAdapter.Model.XunitTestExplorer.TryGetTypeTest(ITypeInfo type, Test assemblyTest)
at Gallio.XunitAdapter.Model.XunitTestExplorer.GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, Boolean populateRecursively)
at Gallio.XunitAdapter.Model.XunitTestExplorer.ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
at Gallio.Model.Helpers.TestExplorer.Explore(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
at Gallio.Model.Helpers.SimpleTestDriver.GenerateTestModel(IReflectionPolicy reflectionPolicy, IEnumerable`1 codeElements, IMessageSink messageSink)
at Gallio.Model.Helpers.SimpleTestDriver.DescribeImpl(IReflectionPolicy reflectionPolicy, IList`1 codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
at Gallio.Model.BaseTestDriver.Describe(IReflectionPolicy reflectionPolicy, IList`1 codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.<>c__DisplayClass17.<DescribeImpl>b__15(ITestDriver driver, IList`1 items, Int32 driverCount)
at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.ForEachDriver[T](MultiMap`2 testFrameworkPartitions, Func`4 func)
--- End of inner exception stack trace ---
at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.ForEachDriver[T](MultiMap`2 testFrameworkPartitions, Func`4 func)
at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.DescribeImpl(IReflectionPolicy reflectionPolicy, IList`1 codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
at Gallio.Model.BaseTestDriver.Describe(IReflectionPolicy reflectionPolicy, IList`1 codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
at nCrunch.TestExecution.Frameworks.Gallio.GallioWrapper.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, String assemblyFilePath, String[] referencedAssemblyFilePaths)
at nCrunch.TestExecution.Frameworks.Gallio.GallioTestFramework.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, String assemblyFilePath, String[] referencedAssemblyFilePaths)
at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, String assemblyFilePath, String[] referencedAssemblyFilePaths, TestFrameworkDescription[] frameworks)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.DiscoverTests(TestFrameworkDescription[] applicableTestFrameworks)
at nCrunch.Compiler.RemoteBuildRunner.#=qc19uOgHz4bbS00fHoJcJ86FdDfZxNpBz6hs6SLcoDgg=(ComponentBuildParameters #=qmVSC1mocuqkeMyG6RiWA7A==, String #=q6HotKBtAzAJ5NhAIJpJMWErw8$oIjiUT0yL0fTvBG1s=, BuildOutput #=qeo8ShH4FE1FNzdVk_FG0_g==, String #=qRmPlD1GldENhQyyoQ5tYKKyaUsmzaLiSqv0FdoKZIHA=, String[] #=qftBQ99WoQMP8nKBadgDENHqcE_v2YLLk_k2_mOUUIoM=)
at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)


Based on this message and another forum post I'm assuming it's some kind of version collision, since the version of xUnit.net in nuget is 1.9.1.

I'm rather keen to leverage some of the auto mocking capabilities that come from combining AutoFixture, xUnit.net, and NSubstitute as seen on Mark Seemann's blog.

I've created a bug report for this issue too.

Remco
#2 Posted : Friday, April 12, 2013 9:55:33 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi, thanks for sharing this issue.

Giving this a quick try, I wasn't able to reproduce the issue. NCrunch's support for Xunit 1.9.1 actually works by redirecting to the 1.9.0 assembly that is packaged with its Gallio components - so it's definitely looking for the right file. The key question is why it cannot find it. Can you perform a quick inspection of your NCrunch installation directory? Have a look under:

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2012\Xunit\Latest"

.. For VS2012, or "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2010\Xunit\Xunit\Latest" for VS2010

Do these directories exist, containing the 1.9.0 Xunit.dll?
aboy021
#3 Posted : Sunday, April 14, 2013 9:30:46 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/24/2013(UTC)
Posts: 19
Location: New Zealand

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
I verified the existence of the Xunit dll.
I had earlier tried an approach I read about in the forums involving upgrading the xunit dll, so in case I'd created new problems I decided to reinstall ncrunch.
After reinstalling ncrunch I verified that the dll was in the extensions folder specified (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2010\Xunit\Latest - please note, one less "Xunit").

My project builds but the test fails with the message:

Quote:
"This test was not executed during a planned execution run. Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures."


I created a new project, added a nuget reference to xunit, and added the source code as above.
I tested the project using the ReSharper test runner, test passes.
I enabled NCrunch and test passes.

I then installed the nuget package "AutoFixture", test passes.
I then installed the nuget package "AutoFixture.Xunit", and test fails with the error:

Quote:
"This test was not executed during a planned execution run. Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures."


From what I've read on the forums I wonder if it's related to assembly bindings in the app.config?
The app.config is below:

Code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="xunit" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.9.1.1600" newVersion="1.9.1.1600" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="xunit.extensions" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.7.0.1540" newVersion="1.7.0.1540" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>


I Commented out the app.config, test passes.


I guess where I am now I have a passing unit test but I've interfered with the installation of a nuget package and I'm worried about what the consequences of doing so will be?
Remco
#4 Posted : Sunday, April 14, 2013 11:10:57 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
It looks as though the Nuget package for AutoFixture is rigged with this deliberately to ensure that you're binding to its version of Xunit. Most probably this was done by the author to limit the potential for cross version issues with this framework. Although I don't know much about the inner workings of AutoFixture, I would expect that if your tests are running without problems, then this is probably nothing to worry about. NCrunch itself also uses binding redirections to force the runtime environment to its own version of Xunit, although in this situation AutoFixture seems to have overridden these.

It's hard to find a truly right answer to this, as what we're observing is effectively a clash between the products (NCrunch/AutoFixture). Each expects a different version of Xunit. There is a task in the backlog to upgrade NCrunch's Xunit support to 1.9.1 with the next minor release, which should solve this temporarily (as at least we'll all be on the same version), although there is still the future potential for version mismatch.

There are plans in the future development of NCrunch to integrate with Xunit directly, and I should be able to include better support for handling cross-version issues when this is implemented ... so I guess a good long term solution is possible. There is the potential that AutoFixture is not the only framework that adds binding redirections of this nature.
aboy021
#5 Posted : Monday, April 15, 2013 10:34:42 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/24/2013(UTC)
Posts: 19
Location: New Zealand

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
Ok, so just to summarise the fix for the moment is to comment out the assembly binding redirects that the nuget package adds to the app.config.

In the future the nature of NCrunch's Xunit support may change and this issue may disappear.

Now that I've got a workaround things are behaving nicely. Thanks.
1 user thanked aboy021 for this useful post.
Remco on 4/15/2013(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.057 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download