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

Notification

Icon
Error

NCrunch, JustMock and xUnit1
GlobalConcepts
#1 Posted : Wednesday, July 18, 2018 12:45:08 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 2/7/2013(UTC)
Posts: 52
Location: Germany

Thanks: 5 times
Was thanked: 6 time(s) in 6 post(s)
Hello,

we just switched from MS Fakes to Telerik JustMock.
Upon that, NCrunch showed the following error:
Quote:

NCrunch: This test was executed on server '(local)'

*** Failures ***

Exception
System.TypeInitializationException: System.TypeInitializationException : Der Typeninitialisierer für "Telerik.JustMock.Core.Context.MockingContext" hat eine Ausnahme verursacht.
---- System.InvalidOperationException : Some attribute type among MbUnit.Framework.SetUpAttribute, mbunit,MbUnit.Framework.TearDownAttribute, mbunit not found.
bei Telerik.JustMock.Core.Context.MockingContext.RetireRepository()
bei Telerik.JustMock.Mock.<>c.<Reset>b__43_0()
bei Telerik.JustMock.Mock.Reset()
bei JustMockWithNCrunch.JustMockTest.TestMethod() in C:\Users\dklinger\Documents\Visual Studio 2017\Projects\JustMockWithNCrunch\JustMockWithNCrunch\JustMockTest.cs:Zeile 15.
----- Inner Stack Trace -----
bei Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.CreateAttributeMatcher(String[] attributeTypeNames)
bei Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.AddRepositoryOperations(String[] attributeTypeNames, Func`2 getKey, Func`3 isInheritingContext, Boolean isLeaf, Boolean isUsedOnAllThreads)
bei Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.SetupStandardHierarchicalTestStructure(String[] testMethodAttrs, String[] testSetupAttrs, String[] fixtureSetupAttrs, String[] assemblySetupAttrs, FixtureConstuctorSemantics fixtureConstructorSemantics)
bei Telerik.JustMock.Core.Context.MbUnitContextResolver..ctor()
bei Telerik.JustMock.Core.Context.MockingContext..cctor()


That one was very unexpected as we are not using the MBUnit-Framework anywhere in our projects.
After further research we discovered the following file within JustMock: https://github.com/teler...bUnitContextResolver.cs
In there it will be checked if the type "Gallio.Framework.Assertions.AssertionException" is present in an assembly "gallio.dll" within the current execution Test-AppDomain.

Digging depper we saw that NCrunch is loading the Gallio-DLL in its nCrunch.TestHost-Process if xUnit1 is used:
[img=(- BROKEN LINK -)]NCrunch-AppDomain using xUnit1[/img]

Because of the existence of the Gallio-DLL - which, as we think, is not needed for xUnit1 - JustMock ist trying to initialize its MBUnitContextResolver and fails on doing this as MBUnit is not present.

The workaround is to enable the NCrunch-option "Pre-load all assembly references into test environment" which is not recommended from your side.

So we have a few questions:
- Is it expected that NCrunch fails with JustMock and xUnit1 without having the Pre-Load-option set?
- Is ist save and recommend to enable the Pre-Load-option in this case?
- Is this some kind of edge-case-bug which you could fix in any way so we don't have to enable the Pre-Load-option as it slows down text execution?

I have a minimal-example available if you want to reproduce the behaviour.

Kind Regards,
Daniel
Remco
#2 Posted : Wednesday, July 18, 2018 12:56:24 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 Daniel,

Thanks for sharing this issue.

NCrunch uses Gallio to integrate with Xunit v1. At the time this was implemented, it was deemed simpler to tie into Gallio and thereby get immediate support for both MbUnit and Xunit at the same time, avoiding the need to integrate with each one separately. We later paid a heavy price for this shortcut. Xunit v2 is done using direct integration and has no reliance on Gallio.

It would take some time on my side to fully reconstruct this issue in order to examine in detail, but I expect that the result of such an understanding would likely arrive at the same conclusion: To handle this use case, you'll need to either leave the Pre-load assembly references setting enabled or switch to a newer version of Xunit.

My best guess here is that JustMock have specialised code intended to enable some kind of feature that interoperates with Gallio. Because this code was never tested with NCrunch, it clashes and throws an exception. By setting NCrunch to pre-load assembly references, you can force the runtime environment to use NCrunch's version of Gallio and other dependencies, enabling tighter control over the test environment.
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.032 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download