Unit Testing ASP.net Web Site Project code stored in App_Code

后端 未结 8 1771
陌清茗
陌清茗 2020-12-01 01:43

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, e

8条回答
  •  温柔的废话
    2020-12-01 02:17

    It is possible to unit test classes stored in the App_Code folder without converting your project to a Web App or moving your classes to a Class Library project.

    All that is necessary is setting the code files' Build Actions to Compile. This will cause Debugging and Unit Testing your website to output a .dll file.

    Now when you reference your website project from the unit test project, the classes in the app_code folder will be visible.

    NOTE:

    Setting your .cs files' Build Action to Compile will cause your website to generate a .dll file on debugging and unit-testing. The .dll file will cause problems when you debug your website because IIS will now find your code in two places, the bin and the App_Code folder and will not know which one to use. I currently just delete the .dll file when I want to debug.

提交回复
热议问题