Build/Test Issues

Path.GetFullPath not returning consistently with MsTest or resharper test runners

Started by Jonh04 on 13,437 views

I'm experiencing some errors with Path.GetFullPath returning different results for ncrunch (thereby failing) compared to resharper testrunner or mstest runner.

Resharper
Path.GetFullPath(@"TestData") "C:\\dev\\photoutil\\PhotoUtil.Tests\\bin\\Release\\TestData" string

Ncrunch
Path.GetFullPath(@"TestData") "C:\Users\user\AppData\Local\NCrunch\5428\98\TestResults\f1ceb244-0af6-4bb7-94f1-02b60037e1d1\Out\TestData" string

This is making my tests fail in ncrunch.
Is this a bug or is there some way for me to fix it?

Best Regards
Johan Nilsson
Hi Johan,

Thanks for posting! Can you share which version of NCrunch you are using to run this test? The version of NCrunch just released (1.40b) includes a change that should hopefully rectify the issue as you've described it.


Cheers,

Remco
Hey Remco!

I'm running 1.40b on Visual Studio 2012 ultimate rc.

Thanks for you quick reply!
Best Regards
Johan
Hi John,

In VS2010, MSTest would always set the current directory to be equal to the MSTest 'Out' directory. NCrunch was modelled from this behaviour, though most likely not all test runners actually do this.

It looks as though the behaviour in this area has changed with the VS2012 release. I'm observing MSTest 2012 now consistently setting the current directory to be equal to the build output directory (as you've described).

I'll note this down for future revision. Thanks for letting me know about the issue! If this issue is affecting your tests, you may be able to work around it by using the BaseDirectory of the current application domain instead.


Cheers,

Remco
Thanks!
Looking forward to future versions, love the software!

I'll look into BaseDirectory and see if I can find a solution.

Johan
Hello!

Tried using the BaseDirectory and it gave the same error but on a different path, am I doing it wroing?
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\tmp\Ncrunch temp\5428\100\TestResults\7bc775b4-3881-4c40-9bfb-6d8ba2609efe\Out\TestData'.

Thanks
Hi Johan,

NCrunch should normally set the AppDomain.CurrentDomain.BaseDirectory to be equal to the build output directory. Can you try the following test with NCrunch and let me know of the result that it gives you? Thanks!

using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject
{
	[TestClass]
	public class AppDomainBaseDirectoryTest
	{
		[TestMethod]
		public void AppDomainBaseDirectoryShouldBeTheSameAsTheBuildOutputDirectory()
		{
			var buildOutputDir = Path.GetDirectoryName(typeof(AppDomainBaseDirectoryTest).Assembly.Location);
			Assert.AreEqual(buildOutputDir, AppDomain.CurrentDomain.BaseDirectory);
		}
	}
}

Edited

The test passed
Thanks. This suggests that NCrunch is setting the AppDomain base directory correctly, though the question is how this is not being recognised by your existing code.

Would you be able to share any of the code you're using to identify the working directory of the test? My original thoughts were that you could use a line such as:

Directory.SetCurrentDirectory(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory));

.. in order to set the current directory to the application domain's base directory. This should then align the Path.GetFullPath method with the VS2012 test runner.
Sure I can share the solution, it's just one of my hobby projects. Let me know how to reach you.
For anyone interested, NCrunch 1.41b has just been released including a fix for the above issue.

Post a reply

Log in to reply.