简体   繁体   English

Visual Studio在Web项目中找不到单元测试

[英]visual studio can't find unit tests in web project

I've created a bunch of unit tests for methods in my web project, but i can't make visual studio find these unit tests. 我为Web项目中的方法创建了很多单元测试,但是我无法让Visual Studio找到这些单元测试。

The unit tests are located in App_Code/Tests/testfile (there's multiple test files under the folder tests) 单元测试位于App_Code / Tests / testfile中(文件夹测试下有多个测试文件)

How do i make visual studio find these tests ? 我如何使Visual Studio找到这些测试?

I tried having a seperate unit test project at first, but i couldn't reference the web project, and therefore not call any of the methods in the .cs files under App_Code. 我最初尝试尝试一个单独的单元测试项目,但我无法引用该Web项目,因此无法在App_Code下的.cs文件中调用任何方法。

重构解决方案,以便将要测试的代码放在一个程序集中,例如从Web项目引用的Dataaccess.dll和在也引用Dataaccess.dll项目的测试项目DataaccessTests中的测试。

I agree with Mathias. 我同意Mathias。 It's a better design to modularize your code in layers. 这是一种更好的设计,可将代码分层进行模块化。 So you create Assemblies for example for your Business logic and your Dataaccess Logic. 因此,您可以为业务逻辑和数据访问逻辑创建程序集。 These are not webbased and are pretty easy to Test. 这些不是基于Web的,很容易测试。 You can add References to this Assemblies and test them. 您可以添加对此程序集的引用并对其进行测试。 If you follow this approach you will have at least 3 Projects: 如果您采用这种方法,则将至少有3个项目:

  1. WebUi WebUi
  2. BusinessLogic 商业逻辑
  3. Dataacces 数据访问

The WebUi Projekt references the BusinessLogic project and the BusinessLogic project references the Dataaccess projekt. WebUi项目引用了BusinessLogic项目,而BusinessLogic项目引用了Dataaccess项目。

In the WebUi Project only do UI related stuff and let the BusinessLogic Layer do the work. 在WebUi项目中,仅执行与UI相关的工作,并由BusinessLogic Layer进行工作。

Hope it helps... 希望能帮助到你...

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

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