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

Notification

Icon
Error

NCrunch runs in different folder than VS Test Runner
MikeWard
#1 Posted : Wednesday, December 28, 2016 3:30:42 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/19/2011(UTC)
Posts: 30
Location: Ann Arbor, MI

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
Ever since v2.5 there has been a group of tests that fail and which passed in previous versions. Today I ran down the issue.

My project uses the NancyFX framework. NancyFX supports dependency injection which is fortunate because it allowed me to resolve this NCrunch issue.

In NancyFX locating assets is generally done by asking Nancy for the root path of the application. While all tests run fine in the Visual Studio test runner, there was a group of tests that would not run in NCrunch. I resolved the issue as follows:

Code:
using System;
using System.IO;
using Nancy;

namespace PortalTests.Modules
{
    public class TestRootPathProvider : IRootPathProvider
    {
        public string GetRootPath()
        {
#if NCRUNCH
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..");
#else
            var path = AppDomain.CurrentDomain.BaseDirectory;
#endif
            return path;
        }
    }
}


I then inject the TestRootPathProvider into my tests.

Why does the Visual Studio Test Runner work differently than NCrunch in this aspect?
Remco
#2 Posted : Thursday, December 29, 2016 3:31:11 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 565 times
Was thanked: 626 time(s) in 602 post(s)
Hi,

Thanks for sharing this issue.

Can you confirm which test framework you're using? I know that in some situations, the AppDomain base directory is inconsistent between MSTest and NCrunch. This is because of the way MSTest handles its 'deployment item' sandboxing, which is different between versions of MSTest and also dependent upon the MSTest configuration file.
MikeWard
#3 Posted : Thursday, December 29, 2016 3:43:31 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/19/2011(UTC)
Posts: 30
Location: Ann Arbor, MI

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
I'm using the built-in testing framework in Visual Studio 2015 with its standard test runner. Not using a third party test runner like Resharper or NUnit.

From the command line:

mstest /?
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0
Remco
#4 Posted : Thursday, December 29, 2016 10:51:02 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 565 times
Was thanked: 626 time(s) in 602 post(s)
Thanks! Are you using the DeploymentItem attribute, or do you have deployment switched on in your VS MSTest test settings?
MikeWard
#5 Posted : Friday, January 06, 2017 4:20:53 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/19/2011(UTC)
Posts: 30
Location: Ann Arbor, MI

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
No to both.
Remco
#6 Posted : Friday, January 06, 2017 11:01:04 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 565 times
Was thanked: 626 time(s) in 602 post(s)
I've had a go at trying to reproduce this issue, but the paths seem to be aligned in my simplistic test cases.

I'm wondering if there might be some aspect of MSTest here that I've overlooked.

When MSTest runs your tests, is it setting the appdomain's base directory to the same directory as the build output directory of the test DLL?
MikeWard
#7 Posted : Wednesday, January 25, 2017 2:37:56 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/19/2011(UTC)
Posts: 30
Location: Ann Arbor, MI

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
Apparently, you found the issue. Updated to 3.3.0.6 and now I have to remove my TestRootPathProvider to get tests to pass.
Remco
#8 Posted : Wednesday, January 25, 2017 10:09:35 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 565 times
Was thanked: 626 time(s) in 602 post(s)
MikeWard;9743 wrote:
Apparently, you found the issue. Updated to 3.3.0.6 and now I have to remove my TestRootPathProvider to get tests to pass.


v3.3.0.6 didn't include any changes to the MSTest adapter. So I guess this one is a mystery. It's possible we haven't seen the last of it.
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.