Nunit 未释放测试中使用的 DLL/无法在拆卸中删除
我有一个应用程序必须与非托管且坦率地说有缺陷的 DLL 交互。
我通过让我的应用程序检查运行 DLL 时的各种错误情况来弥补这一点,例如 DLL 进入无限循环时超时。
我正在尝试在我的应用程序中测试该处理,因此我特意编写了一个 DLL,该 DLL 故意进入无限循环。
在我的单元测试中,我想重命名原始 DLL,复制“损坏的”DLL,运行测试,查看超时代码的工作情况,然后删除损坏的 DLL 并替换原始 DLL。
但是,在我的 TearDown 方法中,我无法删除 DLL,从而出现 UnauthorizedAccessException。我认为这是因为 nUnit 仍然以某种方式“打开”DLL。
如何让 nUnit 释放 DLL?
I have an application which has to interface with an unmanaged, and frankly buggy, DLL.
I've compensated for this by making my application check for all sorts of error conditions on running the DLL, things like timing out in case the DLL has gone into an infinite loop.
I'm trying to test that handling in my application, and so I've deliberately coded a DLL which goes into an infinite loop on purpose.
In my unit test, I want to rename the original DLL, copy in my 'broken' DLL, run the test, see the timeout code work, then remove the broken DLL and replace the original DLL.
However, in my TearDown method I can't delete the DLL, getting an UnauthorizedAccessException. I presume this is because nUnit still has the DLL 'open' in some way.
How can I make nUnit release the DLL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我通过将麻烦的测试分成单独的程序集来解决这个问题。我现在有 3 个测试程序集,其中 1 个包含大部分测试,1 个包含我遇到问题的每个测试。这两个测试都包含 SetUp 和 TearDown 代码,以消除其他测试可能留下的任何混乱。
因此,我仍然不知道如何释放 DLL,但通过将测试移至单独的程序集中,我不再需要这样做。
Well, I worked around it by splitting the troublesome tests into separate assemblies. I now have 3 test assemblies, 1 containing the bulk of the tests, and 1 containing each of the tests I was having trouble with. Both of those tests include SetUp and TearDown code to remove any clutter that may have been left by the other test.
So, I still don't know how to release the DLL, but by moving the tests out into separate assemblies I no longer need to.