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

Notification

Icon
Error

Ncrunch + umbraco tests
xpressivecode
#1 Posted : Monday, February 23, 2015 8:40:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/15/2015(UTC)
Posts: 2
Location: Canada

I'm running into an issue while running some unit tests against my umbraco controllers via ncrunch. When I run them via the built in test explorer, everything works fine. Alternatively, if as suggested, I switch my test project to 'Copy referenced assemblies to workspace', it works. But it's far slower.. to the point that it's not giving me the rapid feedback that I'm looking for.

The issue is:

Could not load the Umbraco.Core.Configuration.UmbracoSettings.IUmbracoSettingsSection from config file, ensure the web.config and umbracoSettings.config files are formatted correctly

You need to include 3 configuration files in order for your umbraco tests to run correctly, while referencing their umbraco.tests.dll assembly.

I've tried adding them in to the "Additional files to include" property for my ncrunch settings, but it doesn't work. I'd like to avoid falling back to including all of the assemblies.

Any suggestions?

Remco
#2 Posted : Monday, February 23, 2015 10:33:27 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for posting.

The 'Copy referenced assemblies to workspace' setting does have a significant impact on performance, as this requires much more to be rebuilt when changes are made.

I'm going to guess that the root problem here is the umbraco configuration files not being in the same directory as the test project DLL when the tests are run. Most likely umbraco is always searching for these files in the AppDomain basedirectory or the current directory.

The key underlying issue here is that because the files belong to one project (your application DLL) but are referenced as part of another project (your test DLL), both of these projects need to be rebuilt with full references copied in order for the files to land in the right place.

If you have access to the code responsible for finding these files, it may be sensible to change it so that it searches in the directory of the DLL they are associated with, rather than the test assembly.

Another option could be to either duplicate these files into your test project (or create a cut-down version of them that will work for testing), then make sure these are marked as copy local.

A more complex but effective solution is to implement setup code inside your test that will seek out the files and copy them into the test project's working directory as part of the test. The NCrunch.Framework library has a method that allows you to find the build output directories of projects being referenced by the test project - see http://www.ncrunch.net/documentation/reference_runtime-framework_environment-class for more information on this one. This will require you to implement NCrunch-specific code inside your test project, though you can easily cover yourself using '#if NCRUNCH' directives so the tests can still work with other runners.
xpressivecode
#3 Posted : Monday, February 23, 2015 10:39:13 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/15/2015(UTC)
Posts: 2
Location: Canada

The config files are included as part of the test project. I've since changed their build output to content and specified that they should always be copied. However, the issue still persists.

What's the difference between the built in test runner found in VS as opposed to what NCrunch is doing?

I'll review the link in the meantime and see if I can't figure out a better solution then included all of the references.

Thanks for the quick reply.
Remco
#4 Posted : Monday, February 23, 2015 10:51:56 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
NCrunch uses an optimised build to try and improve feedback times. Turning on the 'Copy referenced assemblies to workspace' setting disables these optimisations and makes the build behaviour closer to what you would experience when building your project in VS. I recommend having a read of this documentation page - http://www.ncrunch.net/documentation/considerations-and-constraints_assembly-colocation-assumptions .. it explains the behaviour in a bit more detail and gives some more information on how to work around such problems.

In your case, the problem is caused by co-location assumptions of resource files (the .config files) rather than DLLs .. but the principle is much the same. When the 'Copy referenced assemblies to workspace' setting is disabled, NCrunch will suppress the msbuild steps used to copy referenced files into the build output directory of referencing assemblies. This allows it to override the assembly loading behaviour of the CLR at runtime and wire together the test application domain artificially, thereby allowing it to build projects selectively instead of through big rebuild actions. It's always possible to work around NCrunch's behaviour, but sometimes it takes a bit more understanding of what is happening and requires some more effort. Many people are OK with just enabling 'Copy referenced assemblies to workspace' as this gives a quick (if poorly performing) solution.
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.044 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download