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

Notification

Icon
Error

My tests can't find an additionally included file
samholder
#1 Posted : Monday, October 1, 2012 10:38:11 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
My test project contains a zip file with some files in which the tests rely on. The zip file is included in the additional files and appears in the AppData\Local\NCrunch\6276\14\<project> directory (as well as the \AppData\Local\NCrunch\6276\14\<project>\bin\Debug\ directory).

In the test setup we do this:

TestCluster = "TestCluster.zip";
if (!File.Exists(TestCluster))
{
throw new FileNotFoundException(string.Format("TestCluster.zip not found in {0}", Directory.GetCurrentDirectory() + "\\" + TestCluster));
}

which works ok when I run the tests in Resharper, but when I run the tests with NCrunch they fail, and the path in the exception is:

\AppData\Local\NCrunch\6276\14\<Project>\eb433ab4-fa25-41b8-b641-feb7173164cc\Out\TestCluster.zip

which seems to imply that the current directory is set to the test output directory, not the source directory. Have I configured something wrong?

Cheers
Remco
#2 Posted : Monday, October 1, 2012 9:18:26 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 Sam -

NCrunch emulates the deployment behaviour of MSTest, which basically involves setting up a separate sandbox for each test while that test is executed. This can be a source of confusion, as NCrunch also builds its own workspace (so we're basically talking about a sandbox within a workspace). The behaviour of MSTest within these sandboxes is configuration-specific and varies depending upon the version of MSTest used, which makes it very difficult to standardise across test runners.

Try adding an a 'DeploymentItem' attribute to your test, specifying the path to the .zip file. This will make NCrunch's MSTest adapter aware of the file so that it is copied into the MSTest sandbox.

Another option is to use the location of the test project binary when trying to find the file. For example, you can make a call to Assembly.GetExecutingAssembly().Location and use this information to infer the location of the file, assuming it is positioned relative to the test assembly.

I hope this helps!


Cheers,

Remco
1 user thanked Remco for this useful post.
samholder on 10/2/2012(UTC)
samholder
#3 Posted : Tuesday, October 2, 2012 7:23:55 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
Thanks Remco, that has sorted it. I discovered this when I pushed the changes to the build server and it suffered the same issues building with MSTest as NCrunch did.

Much appreciated.

Is there some way to mark a test as needing to run in an isolated way without having to use the attribute from the NCrunch assemblies? Not everyone on my team uses NCrunch and I don't want to introduce that dependency...
Remco
#4 Posted : Tuesday, October 2, 2012 8:35:46 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)
Great to hear - I'm glad that solved the problem.

There are no static references from the NCrunch code into NCrunch.Framework.dll. This means it's possible for you to copy any of the attribute types inside NCrunch.Framework into your own test project and NCrunch will still consider them as though they were the real thing. As long as you name the attributes exactly the same and expose the same information, it should all work without trouble. Here is the declaration for the Isolated attribute if you'd like to include it in your codebase:

using System;

namespace NCrunch.Framework
{
public class IsolatedAttribute: Attribute
{
}
}
samholder
#5 Posted : Tuesday, October 2, 2012 11:16:48 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
Ah thanks, forgot about that little trick. Used it before to fool sliverlight stuff into compiling.

Help much appreciated
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.034 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download