简体   繁体   English

在GAC部署的程序集中测试代码

[英]Testing code in GAC deployed assemblies

Quite often I have unit tests using MSTest for code that is in a GAC deploy assembly. 我经常使用MSTest对GAC部署程序集中的代码进行单元测试。 Typically on my development machine I also have a version of code deployed to the GAC. 通常在我的开发机器上,我也有一个部署到GAC的代码版本。 This results in an issue when making changes in the code under test because the unit tests keep running against the GAC deployed assembly. 这会导致在测试代码中进行更改时出现问题,因为单元测试会继续针对GAC部署的程序集运行。

So, to actually test the changed code I have to re-deploy the assembly to the GAC before running the tests. 因此,要实际测试更改的代码,我必须在运行测试之前将程序集重新部署到GAC。 Thats is quite error-prone and not easy to work with. 多数民众赞成容易出错,不易使用。 Does anyone have a good sugestion on how to work-around this problem? 有没有人对如何解决这个问题有很好的解释? I think simply running GACUtil or similar in the post-build event is not a workable solution as it might cause problems for fellow developers... 我认为在后期构建事件中简单地运行GACUtil或类似程序并不是一个可行的解决方案,因为它可能会给开发人员造成问题......

I would recommend you to never deploy any assemblies into the GAC on your development machine as well as your build server. 我建议您永远不要在开发机器和构建服务器上将任何程序集部署到GAC中。 Use a local copy for third party assemblies or project references while developing. 在开发时使用本地副本用于第三方程序集或项目引用。 This way you know exactly what you are building against and another developer who decides to checkout the code from the repository on his machine will be able to get it running very quickly without the need to install things. 通过这种方式,您可以确切地知道您正在构建的内容,而另一位决定从其计算机上的存储库中签出代码的开发人员将能够在不需要安装的情况下快速运行它。

Assemblies should be placed into the GAC as part of your deployment process only on the target machines. 只应在目标计算机上将程序集作为部署过程的一部分放入GAC。

I find this to be rather annoying as well. 我觉得这也很烦人。 My test project CLEARLY references the PROJECT, not the GAC'ed assembly... I'm unsure whether this is the CLR load process choosing the GAC instead of the local directory, or MSTest indicating a preference (I assume that MSTest isn't handling the appdomain's assembly resolve event, which causes the default behavior to check the GAC first). 我的测试项目CLEARLY引用了PROJECT,而不是GAC的程序集...我不确定这是否是选择GAC而不是本地目录的CLR加载过程,或MSTest指示偏好(我假设MSTest不是处理appdomain的程序集解析事件,这会导致默认行为首先检查GAC)。

I agree that it'd be ideal to have a separate DEV and CI/Test server... but development for SharePoint DOES involve installing assemblies into the GAC on a regular basis (required in some cases), and forcing the developer to retract/uninstall the code before UNIT TESTING, just to ensure that the tests use the correct assembly, is somewhat lame. 我同意拥有一个单独的DEV和CI /测试服务器是理想的...但是SharePoint DOES的开发涉及定期将程序集安装到GAC中(在某些情况下需要),并迫使开发人员撤回/在UNIT TESTING之前卸载代码,只是为了确保测试使用正确的程序集,有点蹩脚。

进行更改时使用其他程序集版本

I agree with Darin and I'd avoid deploying assemblies to the GAC on my dev machine. 我同意Darin,我会避免在我的开发机器上向GAC部署程序集。 Your unit tests have to run against your local assemblies (That's why we call them unit tests, right?). 您的单元测试必须针对您的本地程序集运行(这就是我们称之为单元测试的原因,对吧?)。

If you want to do an integration test with the entire app or parts of it deployed on your machine, just script two gacutil calls that install the assemblies to the GAC, run the tests, then clean up the GAC. 如果要对整个应用程序或部署在计算机上的部分应用程序进行集成测试,只需编写两个gacutil调用脚本,将程序集安装到GAC,运行测试,然后清理GAC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM