存储在APP_ code单元测试ASP.net网站项目code [英] Unit Testing ASP.net Web Site Project code stored in App_Code

查看:113
本文介绍了存储在APP_ code单元测试ASP.net网站项目code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.net网站项目(.NET 3.5)。目前,一切的背后code文件(包括LINQ2SQL的东西,数据环境中,业务逻辑,扩展方法,等等)位于APP_ code文件夹中。非code的

I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code behind code files (including Linq2Sql stuff, data contexts, business logic, extension methods, etc) are located in the App_Code folder.

我感兴趣的是在推动该项目的至少部分路段引入单元测试(使用NUnit)。任何单元测试,我会做需要有完全访问所有当前位于APP_ code文件夹中的code的。我做了一些初步的阅读,到目前为止,共识似乎是:

I am interested in introducing Unit Testing (using nunit) in at least some sections of the project moving forward. Any Unit Testing that I would be doing would need to have full access to all of the code that is currently located in the App_Code folder. I have done some initial reading so far, and the consensus seems to be:


  • 给我的当前设置
  • 这是不可能的
  • 单元测试要求在引用编译的DLL的一部分课程,并通过定义一个网站项目只在编译运行时间。

  • 在为了继续,我将需要将我的整个项目转换为Web应用程序,或者将所有code的,我想测试(即:APP_ code的全部内容)一个类库项目并引用在网站项目的类库项目。无论这些都将提供访问,我需要编译的DLL格式的类,这将让我的单元测试它们。

  • This will not be possible given my current setup
  • Unit testing requires referencing classes that are part of a compiled dll, and a Web Site Project by definition only compiles at run time.
  • In order to proceed, I will need to either convert my entire project to a Web Application, or move all of the code that I would like to test (ie: the entire contents of App_Code) to a class library project and reference the class library project in the web site project. Either of these will provide access to the classes that I need in compiled dll format, which will allow me to Unit Test them.

这是正确的?还是有另一种,我可以单元测试,而不调整/重构我的整个项目的方式?

Is this correct? Or is there another way that I can Unit Test without restructuring/refactoring my entire project?

推荐答案

您的结论看上去是正确的。我将投票支持移动功能整合到一个或几个类库项目,因为这可以打开门重用在其他项目中相同的功能良好。

Your conclusions seem correct. I would vote for moving functionality into one or several class library projects, since that may open the door for reusing the same functionality in other projects as well.

这篇关于存储在APP_ code单元测试ASP.net网站项目code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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