单元测试以验证 WinForms 应用程序不会多次加载程序集 [英] Unit Test to verify that WinForms application doesn't load Assembly more than once

查看:50
本文介绍了单元测试以验证 WinForms 应用程序不会多次加载程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个单元测试 (NUnit),它将:

I am trying to write a unit test (NUnit) that will:

  1. 创建某个表单的实例.
  2. 连接 AppDomain 的相关 AssemblyLoad 事件以构建加载的程序集名称列表.
  3. 如果同一个程序集加载两次,则失败.
  4. 否则 - 通过.

我似乎无法理解这个逻辑......测试总是通过.

I cannot seem to get the logic for this... The test always passes.

这能做到吗?

推荐答案

很难让你的单元测试失败.CLR 已经确保程序集只加载一次.非常重要的是,多次加载相同的程序集会导致在运行时很难诊断转换错误.

It is hard to make your unit test fail. The CLR already makes sure that an assembly only gets loaded once. Pretty important, getting the same assembly loaded more than once produces very hard to diagnose casting errors at runtime.

您必须使用可怕的 Assembly.LoadFile() 来避免失败.避免测试一开始就不应该做的事情.

You'd have to use the horrid Assembly.LoadFile() to trip a fail. Avoid testing things you should never do to begin with.

这篇关于单元测试以验证 WinForms 应用程序不会多次加载程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆