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
Build/Test Issues
My tests can't find an additionally included file
Started by samholder on 8,265 views
Remco NCrunch Developer
#2873
01 Oct 2012 21:18 UTC
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
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
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...
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 NCrunch Developer
#2875
02 Oct 2012 08:35 UTC
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
{
}
}
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
{
}
}
Ah thanks, forgot about that little trick. Used it before to fool sliverlight stuff into compiling.
Help much appreciated
Help much appreciated
Post a reply
Log in to reply.