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

Notification

Icon
Error

Test Using DeployItem attribute throw errors
drdamour
#1 Posted : Tuesday, March 20, 2012 8:18:36 PM(UTC)
Rank: Newbie

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

I'm noticing if my MS unit testing test relies upon the DeployItem (doc'd @ http://msdn.microsoft.com/en-us/library/ms245570.aspx ) attribute to get files in my run path, ncrunch fails on those tests saying that the file doesn't exist.

I've been trying to use the ncrunch config to fix this by adding my SampleDocs folder to the Additional files to include settings with the value SampleDocs\*.*, the ncrunch build succeeds, but during execution it fails with an inability to find my deployment item file. I've been peeking in the output folders and i don't see my files. Any ideas on what i'm doing wrong?
Remco
#2 Posted : Tuesday, March 20, 2012 9:30:18 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, thanks for posting!

NCrunch does support the DeploymentItem attribute, though it needs to be used in combination with the 'additional files to include' or while including the test resources in your project file. So basically, you need to do both of the above things you mentioned to make this work.

Basically, NCrunch needs to shadow-copy your entire project with all of its test resources into the NCrunch workspace. From here, the MSTest runner then needs to shadow-copy the test resources into its own workspace. If you're having trouble, the key thing to check would be which of these two steps is being missed.
drdamour
#3 Posted : Tuesday, March 20, 2012 9:32:37 PM(UTC)
Rank: Newbie

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

I'm pretty sure i have both of this things set, but it's still not working. Are there any logs output during the shadow copy? Would i see the files in the out directory (the running directory)?
Remco
#4 Posted : Tuesday, March 20, 2012 9:42:52 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)
If all is working correctly, you should see the files in both your NCrunch workspace and in the MSTest workspace (the 'Out' directory).

If you set your 'log verbosity' to detailed (NCrunch global configuration), then clicking on the test task in the processing queue should give you detailed information about which files were copied.
digicoder
#5 Posted : Tuesday, May 8, 2012 8:45:37 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/8/2012(UTC)
Posts: 2
Location: Ohio

Thanks: 1 times
Remco;1529 wrote:
If all is working correctly, you should see the files in both your NCrunch workspace and in the MSTest workspace (the 'Out' directory).

If you set your 'log verbosity' to detailed (NCrunch global configuration), then clicking on the test task in the processing queue should give you detailed information about which files were copied.


Setting to Verbosity does not work for me.

I modified my unit test to output the folder it's looking for:

Code:

[TestClass]
public class NhCRUDTests
{
const string NH_TEST_DB = "NhTestDb.sdf";

[DeploymentItem(NH_TEST_DB)]
[ClassInitialize]
public static void FixtureSetup(TestContext context)
{
Assert.IsTrue(File.Exists(NH_TEST_DB), "deployment failed: " + Directory.GetCurrentDirectory() + "\\" + NH_TEST_DB);
new ConfigurationHelper().Configure();


What I get is an output folder where the file is missing:

C:\Users\Robert\AppData\Local\NCrunch\5584\12\TestResults\6640ad3e-27ec-43d6-b933-bb5307679697\Out

What I see when looking at the advanced workspace folder is this:

C:\Users\Robert\AppData\Local\NCrunch\5584\12\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests

The sdf file does exist in the workspace folder
As you can see the Deployment value exists
Deployment is enabled through the Test Settings
The unit test works fine directly
The NCruch additional files is set to "NhTestDb.sdf" and reading the output log, it appears that it goes to the wrong place, it's going to the bin\Debug folder, but not to the actual running test folder

additional entries from the output log

Code:

Target "_CopyOutOfDateSourceItemsToOutputDirectory" skipped, due to false condition; ( '@(_SourceItemsToCopyToOutputDirectory)' != '' ) was evaluated as ( '' != '' ).
Using "Copy" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Copying file from "C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\NhTestDb.sdf" to "bin\Debug\NhTestDb.sdf".
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
Input files: App.config


and the last reference before the failed unit test:

Code:

Using "Delete" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "WriteLinesToFile" skipped, due to false condition; ('@(_CleanUnfilteredPriorFileWrites)'!='@(_CleanUniqueRemainingFileWritesAfterIncrementalClean)') was evaluated as ('C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\obj\Debug\ResolveAssemblyReference.cache;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\NhTestDb.sdf;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\Sfc.Persistence.Nh.UnitTests.dll.config;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\Sfc.Persistence.Nh.UnitTests.dll;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\Sfc.Persistence.Nh.UnitTests.pdb;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\obj\Debug\Sfc.Persistence.Nh.UnitTests.dll;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\obj\Debug\Sfc.Persistence.Nh.UnitTests.pdb'!='C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\obj\Debug\ResolveAssemblyReference.cache;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\NhTestDb.sdf;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\Sfc.Persistence.Nh.UnitTests.dll.config;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\Sfc.Persistence.Nh.UnitTests.dll;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\bin\Debug\Sfc.Persistence.Nh.UnitTests.pdb;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\obj\Debug\Sfc.Persistence.Nh.UnitTests.dll;C:\Users\Robert\AppData\Local\NCrunch\5584\32\Source\Persistence.Providers.NHibernate\Sfc.Persistence.Nh.UnitTests\obj\Debug\Sfc.Persistence.Nh.UnitTests.pdb').
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '' and ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or '$(_AssemblyTimestampBeforeCompile)' != '$(_AssemblyTimestampAfterCompile)')) was evaluated as ('' != '' and ('' != 'OnOutputUpdated' or '' != '')).
#NCRUNCH_OutputFile='bin\Debug\Sfc.Persistence.Nh.UnitTests.dll'



Remco
#6 Posted : Tuesday, May 8, 2012 9:28:11 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, thanks for posting.

It looks as though NCrunch is having difficulty with the DeploymentItem existing on the static fixture setup method. Does this work correctly for you if you move the item to the test method instead?

Thanks!

Remco
1 user thanked Remco for this useful post.
digicoder on 5/9/2012(UTC)
digicoder
#7 Posted : Wednesday, May 9, 2012 2:37:34 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/8/2012(UTC)
Posts: 2
Location: Ohio

Thanks: 1 times
Excellent! I just added the DeploymentItemAttribute to the test method as well as the initializer and it went right through. Works correctly. Thanks alot.
Remco
#8 Posted : Wednesday, May 9, 2012 9:36:59 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)
Thanks! Great to hear. I'll make a note to sort this out so that the DeploymentItem also works on the setup method, as this will be more consistent with MSTest's implementation.

Cheers,

Remco
Remco
#9 Posted : Thursday, May 10, 2012 6:32:32 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 Digicoder -

I've looked into this in a bit more depth, and I've been having trouble getting MSTest to use the DeploymentItem myself when it is applied to a ClassInitialize method. Do you know if there are any circumstances under which this should work? Looking through various scraps of documentation it appears as though MS intended to have this work at fixture level eventually, though I can't find evidence that it was ever implemented. Can you share any more details about the test runner you were using to compare against NCrunch?


Thanks!

Remco

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