NUnit的log4Net问题(已尝试v2.5.7、2.5.2、2.4.8、2.4.7) [英] log4Net issues with NUnit (Tried v2.5.7, 2.5.2, 2.4.8, 2.4.7)

查看:68
本文介绍了NUnit的log4Net问题(已尝试v2.5.7、2.5.2、2.4.8、2.4.7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在针对生产代码程序集运行NUnit时出现错误(请参阅文章底部).生产代码程序集引用了内部使用log4net的第三方框架(具体来说,这是SimplyAccounting的SDK).它使用的log4net版本是1.2.9.0.在我们通过dll文件中的公共api使用的第三方框架之外,log4net不是我们的生产代码的一部分.

I'm getting an error (see bottom of post) when running NUnit against a production code assembly. The production code assembly has a reference to a third party framework that uses log4net internally (Specifically, this is SimplyAccounting's SDK). The version of log4net that it uses is 1.2.9.0. Outside of this third party framework which we use via the public api from the dll files, log4net is not part of our production code.

在进行故障排除时,我从单元测试项目中删除了对生产代码程序集的引用,并添加了对SimplyAccounting SDK的引用.当我这样做时,NUnit会吐出以下错误.如果第三方参考(或生产代码参考)不在测试项目中,则Nunit可以正常运行.有潜在的log4net冲突的任何变通办法将是有帮助的.我正在使用NUnit 2.5.2.

While troubleshooting, I eliminated the reference to the production code assembly from the unit test project and added a reference to the SimplyAccounting SDK. When I do this NUnit pukes out the following error. If the third party reference (or the production code reference) is not in the test project then Nunit runs fine. Any workarounds with a potential log4net conflict would be helpful. I'm using NUnit 2.5.2.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at log4net.Layout.LayoutSkeleton.get_Header()
   at log4net.Appender.TextWriterAppender.WriteHeader()
   at log4net.Appender.TextWriterAppender.set_Writer(TextWriter value)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at NUnit.Core.Log4NetCapture.SetAppenderTextWriter(TextWriter writer)
   at NUnit.Core.Log4NetCapture.StartCapture()
   at NUnit.Core.TextCapture.set_Enabled(Boolean value)
   at NUnit.Core.RemoteTestRunner.StartTextCapture(EventListener queue)
   at NUnit.Core.RemoteTestRunner.BeginRun(EventListener listener, ITestFilter filter)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at NUnit.Core.TestRunner.BeginRun(EventListener listener, ITestFilter filter)
   at NUnit.Core.ProxyTestRunner.BeginRun(EventListener listener, ITestFilter filter)
   at NUnit.Util.TestDomain.BeginRun(EventListener listener, ITestFilter filter)
   at NUnit.Util.TestLoader.RunTests(ITestFilter filter)
   at NUnit.UiKit.TestSuiteTreeView.RunTests(ITest[] tests, Boolean ignoreCategories)
   at NUnit.UiKit.TestSuiteTreeView.RunSelectedTests()
   at NUnit.UiKit.TestTree.RunSelectedTests()
   at NUnit.Gui.NUnitForm.runButton_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

推荐答案

一种解决方案(尽管很具破坏性,但没有解决根本问题),是让您的生产程序集与包装SimplyAccount SDK的接口进行对话,而不是直接对话.做到这一点.然后,您的生产代码不需要引用SDK dll,您可以通过传入所创建接口的伪实现来自由地对其进行测试.

One solution (although pretty disruptive and not solving the root issue) would be to have your production assembly talk to an interface that wraps the SimplyAccount SDK instead of talking directly to it. Then your production code doesn't need to reference the SDK dll and you could test it freely by passing in a fake imlementation of the interface you created.

这具有与该SDK分离的设计优势,但是就像我说的那样,这可能会破坏您的代码库.

This has the design benefit of being decoupled from that SDK, but like I said, it could be quite disruptive to your codebase.

这篇关于NUnit的log4Net问题(已尝试v2.5.7、2.5.2、2.4.8、2.4.7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆