简体   繁体   中英

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.

The unit tests are located in App_Code/Tests/testfile (there's multiple test files under the folder tests)

How do i make visual studio find these tests ?

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项目引用的Dataaccess.dll和在也引用Dataaccess.dll项目的测试项目DataaccessTests中的测试。

I agree with 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. You can add References to this Assemblies and test them. If you follow this approach you will have at least 3 Projects:

  1. WebUi
  2. BusinessLogic
  3. Dataacces

The WebUi Projekt references the BusinessLogic project and the BusinessLogic project references the Dataaccess projekt.

In the WebUi Project only do UI related stuff and let the BusinessLogic Layer do the work.

Hope it helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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