如何验证 NUnit 插件是否已加载?

发布于 2024-10-15 09:02:36 字数 488 浏览 2 评论 0原文

据我所知,包含插件的程序集必须位于 C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\addins 中。我认为我的程序集正在加载,因为我必须先关闭 NUnit-gui,然后才能替换 addins 目录中的程序集。然而,问题是我没有看到插件的任何效果(没有调用任何事件处理程序)

所以如何验证我的插件是否已加载?我'我喜欢使用调试器进行单步调试,但我对打印行调试非常满意。当我尝试执行 File.WriteAllText() 时,插件无法加载,但没有给出任何原因。另外,如何调试加载过程?

NUnit 文档 很有帮助,但在可扩展性方面它们充其量只是简单的框架,并且 NUnit.Core 中的类没有任何可用的智能感知。

From what I can tell, the assembly containing the addin must be located in C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\addins. I think my assembly is being loaded because I have to close NUnit-gui before I can replace the assembly in the addins directory. The problem, however, is that I don't see any of the effects of the addin (None of the event handlers are being called)

So how do I verify that my addin has been loaded? I'd love to step through with the debugger but I'd be perfectly happy with print line debugging. When I tried doing a File.WriteAllText() the addin failed to load but gave no reason. Also, how do I debug the loading process?

The NUnit docs are helpful, but they're bare bones at best when it comes to extensibility and there isn't any intellisense available for classes in NUnit.Core.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じее 2024-10-22 09:02:36

您应该使用一些像这样的跟踪库一个,您可以下载它此处
现在您可以使用这样的 using 语句来装饰相关方法:

using ApiChange.Infrastructure;
class MyAddin
{
   static TypeHashes myType = new TypeHashes(typeof(MyAddin);

   void RelevantMethod()
   {
       using (Tracer t = new Tracer(myType, "RelevantMethod"))
       {
           ....
           if(bLoaded == false)
             t.Error("Could not load adding because of {0}", reason);
       }
   }
}

然后您可以通过环境变量 _TRACE 启用跟踪

set _Trace=debugoutput

可以使用 SysInternals 工具查看 DebugOutput DbgView(无需附加,只需启动它并观察跟踪即可)。
或者跟踪到一个文件

set _Trace=file

跟踪文件位于可执行文件的位置,例如 Nunit.exe.txt。如果将 _TRACE 设置为某个随机字符串,它将跟踪控制台的帮助,并通过 OutputDebugString 为您提供帮助。

为什么要使用这个跟踪库?它实际上是唯一一个能够在您的方法离开时跟踪任何异常的方法。当方法包含像上面这样的用于跟踪的 using 语句时,这确实有效。如果 NUnit 选择忽略您的插件实际上是您的错,您现在就可以查出。
输出将如下所示:

* ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception
18:57:46.665 03064/05180 <{{ >; ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod
18:57:46.668 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod 抛出异常:System.NotImplementedException:嗨,这是一个错误
在 ApiChange.IntegrationTests.Diagnostics.TracingTests.FaultyMethod()
在 ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod()
在 ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod()
在 ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception()
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod 持续时间 2ms
18:57:46.689 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod 持续时间 24ms

这应该可以很容易地找出为什么您的插件根本没有被使用。而且您不需要调试器;-)。

你的,
阿洛伊斯·克劳斯

You should use some tracing library like this one which you can download here.
Now you can decorate your relevant methods with using statements like this:

using ApiChange.Infrastructure;
class MyAddin
{
   static TypeHashes myType = new TypeHashes(typeof(MyAddin);

   void RelevantMethod()
   {
       using (Tracer t = new Tracer(myType, "RelevantMethod"))
       {
           ....
           if(bLoaded == false)
             t.Error("Could not load adding because of {0}", reason);
       }
   }
}

Then you can enable tracing via the environment variable _TRACE

set _Trace=debugoutput

DebugOutput can be viewed with the SysInternals tool DbgView (no attach simply start it and watch the traces).
Or you trace to a file

set _Trace=file

The trace file is located where the executable is e.g. Nunit.exe.txt. If you set _TRACE to some random string it will trace the help to console and OutputDebugString to give you help.

Why this trace library? It is actually the ONLY one which is able to trace any exception when your method is left. This does work when the method contains using statements for tracing like the one above. If it is actually your fault that NUnit does choose to ignore your plugin you can find out now.
The output will look like this:

* ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception
18:57:46.665 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod
18:57:46.668 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod Exception thrown: System.NotImplementedException: Hi this a fault
at ApiChange.IntegrationTests.Diagnostics.TracingTests.FaultyMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception()
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod Duration 2ms
18:57:46.689 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod Duration 24ms

That should make it easy to find out why your Addin was not used at all. And you do not need a debugger ;-).

Yours,
Alois Kraus

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文