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

Notification

Icon
Error

Support for running Moles (Fakes in 2012)
RobertTheGrey
#1 Posted : Tuesday, July 10, 2012 7:55:32 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/10/2012(UTC)
Posts: 6
Location: UK

Thanks: 3 times
Hi there,

Currently, when running tests that use the Moles framework to mock/stub static and sealed types, NCrunch test runner is unable to run those tests. The MSTest runner is capable of running them because it is capable of setting up a hosted process within which it can execute the tests. When running those working tests under NCrunch, you get the following exception:

Microsoft.Moles.Framework.Moles.MoleInvalidOperationException: Moles requires tests to be IN an instrumented process.

In Visual Studio Unit Test, add the following attribute to your unit test method:

[TestMethod]
[HostType("Moles")] // add this attribute
public void Test()
{ ... }

Extensions are also available for most unit test frameworks. Please refer to the Moles manual.

at Microsoft.Moles.Framework.Moles.MoleRuntime.EnsureContext()
at Microsoft.Moles.Framework.Moles.MoleBase`1.GetInstance()
at Microsoft.Moles.Framework.Moles.MoleBase`1.set_InstanceBehavior(IMoleBehavior value)
at Microsoft.Moles.Framework.Moles.MoleBase`1..ctor()

...

Of course, that attribute is already there since the MSTest runner runs them just fine. Is this something you are able to support with NCrunch or will we need to ignore all tests that use this? Ignoring would not be ideal as a large percentage of tests are using Moles to mock out SharePoint libs which are notoriously difficult to test any other way.

Thanks,
Rob
Remco
#2 Posted : Wednesday, July 11, 2012 6:13:10 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Rob,

Thanks for posting! Right now NCrunch does not support Moles or Fakes, as both of these frameworks require a level of integration in order for them to properly operate.

As Moles has been officially deprecated by Microsoft (replaced by Fakes), right now there are no plans to introduce support for it in NCrunch. Sorry, I realise this will make things more difficult for you.

Support for Fakes will be introduced in a future version of NCrunch - when more documentation becomes available on how to properly establish a hosting environment for it.


Cheers,

Remco
RobertTheGrey
#3 Posted : Wednesday, July 11, 2012 6:24:22 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/10/2012(UTC)
Posts: 6
Location: UK

Thanks: 3 times
Thanks for the response Remco :)

I'd like to argue that Moles will be around a lot longer than it'll take Fakes to get established. Moles hasn't been depricated other than that they won't introduce latest changes (including the name change) into VS2010 or VS2008, but one thing is obvious, significantly more people have invested in Moles than have done so in Fakes of course. There are a VAST number if enterprise shops still running on VS2008, and a significant number who have moved to VS2010.

This is a big decision as I'm sure you're aware and *most* will not be moving to VS11 any time soon. That means that there is at least a 2-3 year window where Moles support will be welcomed.

Lastly - I'm not sure if it's possible because I haven't seen the internals, but given that the MSTest runner runs these tests perfectly well, is it not somehow possible to piggyback off of that by running it using that runner instead of the NCRunch runners where you see the special Attribute used? This would solve the need for you to wait to find out how the hosted process works. Could be a great shortcut if it's possible to invoke programmatically.

Thanks again for a great tool!
Rob
Remco
#4 Posted : Wednesday, July 11, 2012 6:48:28 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Rob,

Thanks for your understanding. Right now the main issue with NCrunch is that it's an extremely integrated product, and every new integration point needs to be carefully tested, maintained and supported. Mocking frameworks in general can be challenging to integrate with NCrunch due to the level of manipulation performed by NCrunch over the testing process. I did at same stage spend several hours attempting to integrate with Moles but quickly identified that it would not be an easy task. I'm expecting that Fakes will be equally painful, but it is also in the main path of future growth, so it will need to be supported eventually.

So at some stage, the battles do need to be picked carefully. I realise that every framework NCrunch isn't integrated with will result in problems for a certain percentage of developers in their adoption of the tool, and this needs to be balanced carefully against spending more time investing in the features that make NCrunch a valuable product.


Cheers,

Remco
1 user thanked Remco for this useful post.
RobertTheGrey on 7/11/2012(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.039 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download