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

Notification

Icon
Error

Unit Test execution and data folders
cbretana
#1 Posted : Monday, February 26, 2018 5:28:05 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/20/2014(UTC)
Posts: 6
Location: United States of America

Thanks: 1 times
Running NUnit 3.0 tests in NCrunch within Visual Studio 2017 using .Net Framework 4.61,

When a unit test needs to read or write a data file to a project folder, I am getting
System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Data\LAS\Builds\Output\TestBin\Debug\11164\44\_ncrunchreferences\Data\Notification'.

My Visual Studio solution is building the test harness projects into the folder [C:\Data\LAS\Builds\Output\TestBin\Debug] and the folder the test data files are being dumped into is [C:\Data\LAS\Builds\Output\TestBin\Debug\Data\Notification]

And the tests all run and pass in NUnit 3.0. But somehow, when NCrunch runs the tests, they fail with the above error message

The bold, italicized part of the error message indicates that NCrunch is looking for the files in a new folder structure.

So, something (Assuming this is NCrunch), is creating this entire folder structure under my Debug folder, with numerical folder names.
If it is NCrunch doing this, why is NCrunch creating this folder structure? and why is this looking in this folder? and what do I do to fix this?
Remco
#2 Posted : Monday, February 26, 2018 10:54:57 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 691 times
Was thanked: 840 time(s) in 800 post(s)
Hi, thanks for posting.

When it runs your tests, NCrunch will create a 'workspace' containing all your project files. This is essentially a sandbox in another area of your HDD. The project will be compiled in this workspace and any tests contained in it will also be run there. When the tests are run, NCrunch specifically sets the current directory to be the build output directory in the workspace.

The path you've given above seems to be malformed. This isn't referencing the NCrunch workspace (unless you've configured your workspace to something very strange), though the bottom three directories should normally exist in the workspace.

Note that when NCrunch sets the current directory, it does so at the start of the test run. If there is any code in any test that changes the current directory, NCrunch can't automatically set this back. This makes it possible for a test in your solution to 'corrupt' the current directory and cause downstream problems in your test run. The directory name you've described looks to me like it's been constructed by code making assumptions about the test environment that don't hold true under NCrunch. I recommend closely examining where this path came from as it seems to be that there is some complexity behind it.

See here for more information about workspacing - http://www.ncrunch.net/documentation/concepts_workspaces.
cbretana
#3 Posted : Monday, February 26, 2018 11:50:14 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/20/2014(UTC)
Posts: 6
Location: United States of America

Thanks: 1 times
Yes, in order to make sure that NUnit 3.x will be able to find the files, I had to use an absolute file path based on the expression
NUnit.Framework.TestContext.CurrentContext.TestDirectory, as using relative paths was causing another problem. And when I look at the folder referenced by the expression above (in the error message), I fiond that NCrunch, has actually copied all the data files to:

C:\Data\LAS\Builds\Output\TestBin\Debug\11164\44\_ncrunchreferences\Builds\Output\TestBin\Debug\Data\Notification

Noptice that part of the path relative to the test execution root (Builds\Output\TestBin\Debug) is repeated twice.
Now the actual running code is looking in the place I expect the files to be, (C:\Data\LAS\Builds\Output\TestBin\Debug\11164\44\_ncrunchreferences\Data\Notification), the code indicates that it is looking (and failing to find them) in the correct place, apparently because NCrunch has copied them to this weird corrupted path specification.

I have set the configuration setting in NCrunch to include these files by setting the "Additional Files to include" setting for this test project to "Data\Notification\**.*"
Could this be causing the problem?
Remco
#4 Posted : Tuesday, February 27, 2018 1:58:11 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 691 times
Was thanked: 840 time(s) in 800 post(s)
The only files that NCrunch itself will normally copy to _ncrunchreferences are the DLLs that are being statically referenced by your code. If you have other files under this directory, then these files won't be copied directly by NCrunch. It's possible you have a malfunctioning build step or custom code (perhaps a third party library) that is using the path of a statically referenced DLL as the drop-point for other related files. Turning on the 'Copy referenced assemblies to workspace' setting will turn off NCrunch's build optimisations here and may give you a workaround for the problem, but I would recommend trying to find the code responsible for copying those files. Although NCrunch is almost certainly executing this code, it isn't inside NCrunch's logic.

I'm also not sure if you intended for NCrunch's workspaces to be stored under C:\Data\LAS\Builds\Output\TestBin\Debug, as this doesn't seem right. If this is actually your workspace base path, you might want to change it to something more isolated - http://www.ncrunch.net/documentation/reference_global-configuration_workspace-base-path.
cbretana
#5 Posted : Tuesday, February 27, 2018 2:52:32 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/20/2014(UTC)
Posts: 6
Location: United States of America

Thanks: 1 times
Thanks! Several ideas here to try. "C:\Data\LAS\Builds\Output\TestBin\Debug" is the output folder for the test harness build process. So it is the folder where the tests execute in when running under NUnit-ReSharper test harness. I was trying to get NCrunch to copy the data files to whatever directory folder it is executing the tests in.

I will implement your suggestions and see what I get.
Users browsing this topic
Guest (3)
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.040 seconds.