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

Notification

Icon
Error

NCrunch and Smart Unit Tests
glinkot
#1 Posted : Sunday, January 11, 2015 9:15:11 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/11/2015(UTC)
Posts: 8
Location: Australia

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hi,

I only purchased NCrunch yesterday so please be gentle! I have installed the VS2015 Ultimate Preview and was keen to try the 'smart unit tests' to pin down some code and avoid regressions during a change I need to make.

I followed the following steps to test the Smart Unit tests, but have then enabled NCrunch and get the errors shown:

1) Create class library project.
2) Create a nonsense class with a few conditionalities to see what tests it whips up:

public string IsItGood(string input)
{
if (input == null) return "its bad";
if (input == "good") return "it's good";
if (input.Contains("oo")) return "It has an oo in it, and is good";
if (input.StartsWith("a")) return "It starts with a and is good";
return "its bad";
}

public string IsItReallyGood(string input)
{
if (input == "really good") return "it's really good";
return "its not really good, but may be good";
}
}

3) Right click the class title and select 'smart unit tests'. Highlight them in the new panel and click the disk to 'save' them into a test project.

4) Running these in the internal test runner works fine.

In NCrunch however it says "1 Project is failing to build" and I get the following issues. The assembly refs are there, so I'm not sure if I'm doing something silly or if this just isn't yet supported. I figure it may be to do with absolute paths and the 'ghost copy' not having certain dependencies. Any tips appreciated.


NCrunch: If you are experiencing problems in getting this project to build, have a look at http://www.ncrunch.net/d...ng_project-build-issues
Properties\PexAssemblyInfo.cs (8): The type or namespace name 'PexAssemblySettings' could not be found (are you missing a using directive or an assembly reference?)
Properties\PexAssemblyInfo.cs (11): The type or namespace name 'PexAssemblyUnderTest' could not be found (are you missing a using directive or an assembly reference?)
Properties\PexAssemblyInfo.cs (14): The type or namespace name 'PexCreatableFactoryForDelegates' could not be found (are you missing a using directive or an assembly reference?)
Properties\PexAssemblyInfo.cs (17): The type or namespace name 'PexAllowedContractRequiresFailureAtTypeUnderTestSurface' could not be found (are you missing a using directive or an assembly reference?)
Properties\PexAssemblyInfo.cs (18): The type or namespace name 'PexAllowedXmlDocumentedException' could not be found (are you missing a using directive or an assembly reference?)
Properties\PexAssemblyInfo.cs (8): The type or namespace name 'TestFramework' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (4): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Class1Test.cs (5): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Class1Test.IsItGood.g.cs (1): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Class1Test.IsItReallyGood.g.cs (1): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Properties\PexAssemblyInfo.cs (2): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Properties\PexAssemblyInfo.cs (3): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Properties\PexAssemblyInfo.cs (4): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Properties\PexAssemblyInfo.cs (5): The type or namespace name 'Pex' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Class1Test.cs (12): The type or namespace name 'PexClass' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (13): The type or namespace name 'PexAllowedExceptionFromTypeUnderTest' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (14): The type or namespace name 'PexAllowedExceptionFromTypeUnderTest' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (13): The type or namespace name 'AcceptExceptionSubtypes' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (17): The type or namespace name 'PexMethod' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (18): The type or namespace name 'PexAssumeUnderTest' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (24): The type or namespace name 'PexMethod' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.cs (25): The type or namespace name 'PexAssumeUnderTest' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (18): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (28): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (38): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (48): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (58): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (68): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItGood.g.cs (78): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItReallyGood.g.cs (18): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)
Class1Test.IsItReallyGood.g.cs (28): The type or namespace name 'PexGeneratedBy' could not be found (are you missing a using directive or an assembly reference?)


WARNING - ..\..\..\..\..\..\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets (1811): Could not resolve this reference. Could not locate the assembly "Microsoft.Pex.Framework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Remco
#2 Posted : Sunday, January 11, 2015 9:44:30 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi, thanks for posting!

It looks like the Pex code generator is placing a 'dangerous' reference to the Pex assembly inside the generated project file. If you open the project file, you'll see something like this:

<Reference Include="Microsoft.Pex.Framework">
<HintPath>..\..\..\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.Pex.Framework.dll</HintPath>
</Reference>

Notice that the HintPath for the above reference is using a relative file path. In most cases, relative file paths are perfectly safe and should be used where possible .. but libraries under Program Files are an exception to this, as they need to be referenced from the same place regardless of the location of the project being built. If this project is ever moved from its original location, the above declaration it will cause it to fail to build.

NCrunch normally rewrites assembly references to handle situations like this, but the above is a special case because the reference points towards Program Files - making it an SDK reference that NCrunch believes should be left alone.

The simple solution to this is to just fix up the reference so that it uses an absolute path. For example:

<Reference Include="Microsoft.Pex.Framework">
<HintPath>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.Pex.Framework.dll</HintPath>
</Reference>

Thanks for providing the steps to reproduce the problem. This always makes things easier!


Cheers,

Remco
glinkot
#3 Posted : Sunday, January 11, 2015 9:57:09 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/11/2015(UTC)
Posts: 8
Location: Australia

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Excellent, that does the trick! I guess if they leave that hardcoded when they release, an exception of some sort might be worth putting in so it treats this case differently.

Appreciate the lightning fast reply!
1 user thanked glinkot for this useful post.
Remco on 1/11/2015(UTC)
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.052 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download