简体   繁体   English

在哪里放置单元测试项目

[英]Where to place unit test project

I'm thinking about where to put the unit/integration test project. 我正在考虑在哪里放置单元/集成测试项目。 I follow the 1 test project pr. 我按照1测试项目pr。 project convention 项目惯例

I can think of 3 ways, that all seems good to me, which make it kind of hard to choose :-) 我可以想到3种方式,这对我来说似乎都很好,这使得它很难选择:-)

  1. Test project is put under a Tests sub folder to the project it tests. 测试项目放在Tests子文件夹下,以测试它的项目。
  2. Test project is put next to the project it tests, in a "project".Tests folder. 测试项目放在它测试的项目旁边的“项目”.Tests文件夹中。 I believe this is what Roy Osherove recommends. 我相信这是Roy Osherove推荐的。
  3. Put all test projects in a sub folder in the root. 将所有测试项目放在根目录中的子文件夹中。 eg \\Tests\\"project".Tests 例如\\测试\\“项目”。测试
  4. Something else? 别的什么?

What you choose and why? 你选择什么,为什么?

Option 2 is my preferred one. 选项2是我的首选。 Aside from anything else, it's just the default when you create a new class library project - it's under the same solution directory as the production project(s). 除此之外,它只是创建新类库项目时的默认设置 - 它与生产项目位于同一个解决方案目录下。

To counter the argument about checking out a project without its tests, I find it relatively rare to check out just a project rather than a whole solution. 为了解决关于在没有测试的情况下签出项目的争论,我发现仅仅检查项目而不是整个解决方案是相对罕见的。 If you're a more "project-based" than "solution-based" shop, that could change things. 如果你是一个更“基于项目”而不是“基于解决方案”的商店,那可能会改变一切。

I like to have all projects in the same level physically. 我喜欢将所有项目都放在同一级别。 I have no big argument, just for simplicity. 我只是为了简单而没有大的争论。 After all visual studio shows all projects in the same level. 毕竟视觉工作室显示了同一级别的所有项目。

.../Project/Project.Web/
.../Project/Project.Model/
.../Project/Project.DataAccess/
.../Project/Project.UnitTest/
etc

Test project is put next to the project it tests, in a "project".Tests folder. 测试项目放在它测试的项目旁边的“项目”.Tests文件夹中。 I believe this is what Roy Osherove recommends. 我相信这是Roy Osherove推荐的。

This is my personal favorite. 这是我个人的最爱。 Its the one that conveys most clearly the intent, and also makes it easy to see at a glance what test projects go with which projects if you're looking at them inside a directory, or have some reason for grouping projects into a single solution. 它是最清楚地传达意图的那个,并且如果你在一个目录中查看它们,或者有一些理由将项目分组到一个解决方案中,也可以很容易地看到哪些测试项目与哪个项目有关。

I'd go with #1 so that when you do a checkout of the project, you have the tests as well. 我会选择#1,这样当您结账时,您也可以进行测试。 Otherwise, tests become even MORE of an afterthought. 否则,测试甚至会成为事后的想法。

The default in a Visual Studio 2010 Asp.Net MVC solution is a different project within the same solution. Visual Studio 2010 Asp.Net MVC解决方案中的默认设置是同一解决方案中的另一个项目。 This is a big help when it comes to testing compilation with all your references. 在使用所有引用测试编译时,这是一个很大的帮助。

I believe option 2 is the best choice. 我相信选项2是最好的选择。 Tests are a great way to document code. 测试是记录代码的好方法。 They make clear the semantics of methods and classes. 他们明确了方法和类的语义。 It should be easy for a programmer to jump to the test code for some method he finds dubious. 程序员应该很容易跳转到他认为可疑的某种方法的测试代码。

On the other way, keeping the test code in the same project may make the compiled binary output bigger and force the project to have dependencies needed only by the test code. 另一方面,将测试代码保留在同一个项目中可能会使编译的二进制输出更大,并迫使项目只有测试代码才需要依赖项。

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

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