据我所知,包含加载项的程序集必须位于C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\addins中。我认为我的程序集正在加载,因为我必须关闭NUnit-gui才能替换外接程序目录中的程序集。但是,问题是我没有看到加载项的任何效果(没有调用任何事件处理程序)。
那么,如何验证我的加载项是否已经加载了呢?,我很想使用调试器,但是我很乐意对打印行进行调试。当我尝试执行File.WriteAllText()时,外接程序未能加载,但没有给出原因。另外,如何调试加载过程?
NUnit文档是有用的,但在扩展性方面,它们充其量是最基本的,而且NUnit.Core中的类也没有任何智能感知。
发布于 2011-02-06 21:25:36
您应该使用类似于这个一的跟踪库,您可以下载这里。现在,您可以使用如下语句来修饰相关方法:
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=debugoutputDebugOutput可以使用SysInternals工具DbgView查看(没有附加,只需启动并查看跟踪)。或者追踪到一个文件
set _Trace=file跟踪文件位于可执行文件的位置,例如Nunit.exe.txt。如果您将_TRACE设置为一些随机字符串,它将跟踪帮助到console,而OutputDebugString将为您提供帮助。
为什么是这个跟踪库?实际上,它是唯一能够在方法被保留时跟踪任何异常的。当方法包含使用语句进行跟踪时,这是可行的,就像上面的语句一样。如果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: Hi aApiChange.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持续时间2ms 18:57:46.689 03064/05180 <}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod持续时间24 2ms
这将使您很容易了解为什么根本不使用Addin。并且您不需要调试器;-)。
你的,Alois Kraus
https://stackoverflow.com/questions/4869986
复制相似问题