NUnit 有时以“无法定位夹具”结尾
Posted
技术标签:
【中文标题】NUnit 有时以“无法定位夹具”结尾【英文标题】:NUnit sometimes ends with "unable to locate fixture" 【发布时间】:2015-01-29 07:33:34 【问题描述】:NUnit-console 2.6.3 有时会打印出以下错误消息,而不是运行测试。以下是我的 Jenkins 测试构建日志的摘录:
00:05:02.982 Process 'nunit-console-x86' [PID 3684] has begun profiling.
00:05:03.698 NUnit-Console version 2.6.3.13283
00:05:03.698 Copyright (C) 2002-2012 Charlie Poole.
00:05:03.698 Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
00:05:03.698 Copyright (C) 2000-2002 Philip Craig.
00:05:03.698 All Rights Reserved.
00:05:03.698
00:05:03.698 Runtime Environment -
00:05:03.701 OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
00:05:03.701 CLR Version: 2.0.50727.5485 ( Net 3.5 )
00:05:03.701
00:05:03.795 ProcessModel: Default DomainUsage: Single
00:05:03.795 Execution Runtime: net-3.5
00:05:33.886 Unable to locate fixture
00:05:33.895 Process 'nunit-console-x86' [PID 3684] has finished profiling.
它随机发生。我不会更改测试程序集或 NUnit 配置。我通过 NCover 运行 NUnit,但是当我从命令行单独使用 NUnit 时,同样的问题会重复。
在 NUnit 中启用详细日志记录后,我注意到 nunit-agent 进程在 nunit-console 运行半分钟后将其第一条消息打印到日志中。我从源代码中发现,nunit-console 等待 30 秒,让生成的 nunit-agent 进程自行注册。显然,有些东西会延迟加载 nunit-agent,因此在 nunit-console 中会遇到超时,从而导致“无法定位夹具”。之后 nunit-agent 进程仍在运行,我必须手动将其杀死。
NUnit-控制台日志:
InternalTrace: Initializing at level Verbose
09:14:08.992 Info [ 1] Runner: NUnit-console.exe starting
09:14:09.006 Debug [ 1] ServiceManager: Added SettingsService
09:14:09.006 Debug [ 1] ServiceManager: Added DomainManager
09:14:09.007 Debug [ 1] ServiceManager: Added ProjectService
09:14:09.007 Debug [ 1] ServiceManager: Added AddinRegistry
09:14:09.007 Debug [ 1] ServiceManager: Added AddinManager
09:14:09.007 Debug [ 1] ServiceManager: Added TestAgency
09:14:09.008 Info [ 1] ServiceManager: Initializing SettingsService
09:14:09.008 Info [ 1] ServiceManager: Initializing DomainManager
09:14:09.008 Info [ 1] ServiceManager: Initializing ProjectService
09:14:09.008 Info [ 1] ServiceManager: Initializing AddinRegistry
09:14:09.008 Info [ 1] ServiceManager: Initializing AddinManager
09:14:09.009 Debug [ 1] ServiceManager: Request for service IAddinRegistry satisfied by AddinRegistry
09:14:09.017 Info [ 1] ServiceManager: Initializing TestAgency
09:14:09.041 Debug [ 1] ServiceManager: Request for service ProjectService satisfied by ProjectService
09:14:09.054 Debug [ 1] RuntimeFrameworkSelector: Current framework is net-3.5
09:14:09.054 Debug [ 1] RuntimeFrameworkSelector: No specific framework requested
09:14:09.054 Debug [ 1] ServiceManager: Request for service ISettings satisfied by SettingsService
09:14:09.058 Debug [ 1] RuntimeFrameworkSelector: Assembly D:\Jenkins\jobs\Job1\GreyBoxTests\bin\Debug\GreyBoxTests.dll uses version 4.0.30319
09:14:09.064 Debug [ 1] ServiceManager: Request for service TestAgency satisfied by TestAgency
09:14:09.065 Debug [ 1] RuntimeFrameworkSelector: Test will use net-4.0 framework
09:14:09.066 Info [ 1] ProcessRunner: Loading GreyBoxTests.dll
09:14:09.067 Info [ 1] TestAgency: Getting agent for use under net-4.0
09:14:09.070 Debug [ 1] TestAgency: Using nunit-agent at c:\Program Files (x86)\NUnit 2.6.3\bin\nunit-agent-x86.exe
09:14:09.091 Info [ 1] TestAgency: Launched Agent process 7240 - see nunit-agent_7240.log
09:14:09.091 Info [ 1] TestAgency: Command line: "c:\Program Files (x86)\NUnit 2.6.3\bin\nunit-agent-x86.exe" 65bc321d-e7dc-4a98-81e6-919b87d5c783 tcp://127.0.0.1:56614/TestAgency
09:14:09.091 Debug [ 1] TestAgency: Waiting for agent 65bc321d-e7dc-4a98-81e6-919b87d5c783 to register
09:14:39.091 Info [ 1] Runner: NUnit-console.exe terminating
NUnit-agent 日志:
InternalTrace: Initializing at level Verbose
09:14:41.859 Info [ 1] NUnitTestAgent: Agent process 7240 starting
09:14:41.876 Info [ 1] NUnitTestAgent: Running under version 4.0.30319.18444, Net 4.5
09:14:41.876 Info [ 1] NUnitTestAgent: Adding Services
09:14:41.876 Debug [ 1] ServiceManager: Added SettingsService
09:14:41.877 Debug [ 1] ServiceManager: Added ProjectService
09:14:41.877 Debug [ 1] ServiceManager: Added DomainManager
09:14:41.877 Debug [ 1] ServiceManager: Added AddinRegistry
09:14:41.877 Debug [ 1] ServiceManager: Added AddinManager
09:14:41.877 Info [ 1] NUnitTestAgent: Initializing Services
09:14:41.878 Info [ 1] ServiceManager: Initializing SettingsService
09:14:41.878 Info [ 1] ServiceManager: Initializing ProjectService
09:14:41.878 Info [ 1] ServiceManager: Initializing DomainManager
09:14:41.878 Info [ 1] ServiceManager: Initializing AddinRegistry
09:14:41.878 Info [ 1] ServiceManager: Initializing AddinManager
09:14:41.879 Debug [ 1] ServiceManager: Request for service IAddinRegistry satisfied by AddinRegistry
09:14:41.906 Info [ 1] NUnitTestAgent: Connecting to TestAgency at tcp://127.0.0.1:56614/TestAgency
09:14:41.907 Info [ 1] NUnitTestAgent: Starting RemoteTestAgent
09:14:41.908 Info [ 1] RemoteTestAgent: Agent starting
任何 NUnit 专家都可以帮助我吗?
【问题讨论】:
NUnit 开发人员最有能力回答这个问题,尽管他们在 SO 上并不活跃。然而,他们对discussion group 的反应非常好。如果您在这里没有得到答案,请尝试那里,如果他们能够提供帮助,请务必在此处跟进! 谢谢帕特里克,我会在那里发布我的问题。 这里是相关帖子的链接:groups.google.com/d/msg/nunit-discuss/g9xTtq1n75w/P39y2V7k4JMJ 【参考方案1】:Charlie 在that Google Groups thread 中建议的潜在解决方法:
避免这种情况的一种方法是停止使用代理。更改配置文件 (nunit-console-x86.exe.config) 在 2.0 CLR 之前使用 4.0 CLR。然后 测试将在同一进程中运行,并且不会创建代理。
我已经确认在 nunit-console.exe.config 文件(或 nunit-console-x86.exe.config)中的 <startup>
中添加 <supportedRuntime version="v4.0.30319" />
并删除 <supportedRuntime version="v2.0.50727"
(如果存在)确实会导致我在不产生 nunit-agent.exe 进程的情况下运行测试。在我的情况下,我还没有确认这是否修复了“无法定位夹具”的错误,但 OP (krzysiek_w) 确实在同一个线程中确认了它:
我不知道在没有 nunit-agent 的情况下在 nunit-console 中运行测试的可能性。在 nunit-console 配置文件中设置支持的框架后,测试执行而不创建完全解决问题的单独进程。
作为附加说明,可以将选项 /trace=Verbose
传递给 NUnit 以获取更多信息,就像 krzysiek_w 在该线程中所做的那样。对我来说,这些日志输出到C:\Users\(myuser)\AppData\Local\NUnit\logs
。
【讨论】:
以上是关于NUnit 有时以“无法定位夹具”结尾的主要内容,如果未能解决你的问题,请参考以下文章
Linux 期望脚本有时以“连接被外国主机关闭”结尾,这是期望脚本还是设备问题?