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

Notification

Icon
Error

Path.GetFullPath not returning consistently with MsTest or resharper test runners
Jonh04
#1 Posted : Wednesday, June 20, 2012 9:26:06 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
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
Remco
#2 Posted : Wednesday, June 20, 2012 11:01:05 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)
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
Jonh04
#3 Posted : Thursday, June 21, 2012 8:57:27 AM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
Hey Remco!

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

Thanks for you quick reply!
Best Regards
Johan
Remco
#4 Posted : Friday, June 22, 2012 2:08:03 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 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
Jonh04
#5 Posted : Friday, June 22, 2012 9:21:51 AM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
Thanks!
Looking forward to future versions, love the software!

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

Johan
Jonh04
#6 Posted : Monday, July 2, 2012 2:06:11 AM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
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
Remco
#7 Posted : Monday, July 2, 2012 4:17:18 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 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!

Code:
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);
		}
	}
}
Jonh04
#8 Posted : Monday, July 2, 2012 12:02:07 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
The test passed
Remco
#9 Posted : Tuesday, July 3, 2012 8:33:23 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)
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.
Jonh04
#10 Posted : Tuesday, July 3, 2012 10:16:39 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
Sure I can share the solution, it's just one of my hobby projects. Let me know how to reach you.
Remco
#11 Posted : Monday, August 13, 2012 4:06:53 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)
For anyone interested, NCrunch 1.41b has just been released including a fix for the above issue.
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.049 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download