Nunit - TestContext.CurrentContext.Test 不起作用
我正在使用 nunit 2.5.9.10348 并尝试在 TearDown 事件中提取当前测试名称,以便我可以将测试名称分配给屏幕截图文件名,但它始终为空(请参阅附图)。私有 _context 变量确实有 TestName 但这对我来说没有用!
有没有人成功使用这个新的 TestContext 功能(来自2.5.7)。
I am using nunit 2.5.9.10348 and trying to extract the current test name in the TearDown event so I can assign a screengrab filename the test name however it is always null (see the attached image). The private _context variable does have the TestName however this is no use to me!
Has anyone had success using this new TestContext functionality (from 2.5.7).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从您的屏幕截图中我看到 _context 有键“TestName”和“Properties”。但是 TestAdapter 会查找键“Test.Name”作为“Name”,“Test.Properties”作为“Properties”。因此,TestContext 初始化有问题(我认为将错误的数据放入 Remoting.Messaging.CallContext)。
经过一番调查(见评论):
NUnit 测试应由 NUnit 测试环境运行,以便上下文可用。
From your screenshot I see that _context has keys "TestName" and "Properties". But TestAdapter looks for keys "Test.Name" for Name and "Test.Properties" for Properties. So, there is something wrong with TestContext initialization (I think wrong data was put to Remoting.Messaging.CallContext).
After a little investigation (see comments):
NUnit tests should run by NUnit testig environment for Context to be available.
我有同样的问题。它发生在我在 TearDown 方法中执行方法时,这实际上是为了进行拆卸,
我不知道为什么,但看起来是这样。是你的情况吗?
更新:现在我查看了屏幕截图,所以这不是你的情况:)
I had the same issue. It occurred when in a TearDown method I executed method, which actually was to make the teardown
I have no idea why, but it seemed so. Is it your case?
UPDATE: Now I looked at the screenshot, so it's not your case :)
R# 测试运行程序存在同样的问题。刚刚下载了 NUnit 源代码并在 TestAdapter 中添加了一个解决方法,使其可以与 r# 一起使用
Same issue with R# test runner. Just downloaded NUnit sources and added a workaround in TestAdapter to make it work with r#