你如何设置你的单元测试项目在.net(S)? [英] How do you Setup your Unit Test Project(s) in .Net?

查看:145
本文介绍了你如何设置你的单元测试项目在.net(S)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以共享的方式,你的.NET解决方案中设置单元测试的项目?

Can you share the way you setup your unit test projects within your .net solutions?

我可以想像几种可能的方法。例如:

I can imagine several possible methodologies. For example:

  1. 有单元测试一个单独的解决方案,完美的镜像原来code解决方案的结构正在测试中。

  1. Having a separate solution for unit tests, perfectly mirroring the structure of the original code solution being tested.

在原来的code解决方案,有一个解决方案文件夹中,你完全镜像...

Inside the original code solution, have a solution folder in which you're perfectly mirroring...

有一个单元测试项目为每个code项目和居住沿着它的解决方案的树结构中。

Have a unit test project for each code project and residing alongside it inside the solution's tree structure.

有一个单元测试项目涵盖居住与他们一起在树结构中的几个code项目。

Have a unit test project covering several code projects residing alongside them in the tree structure.

很想听听你是如何真正做在您的解决方案。

Would love to hear how you're actually doing it in your solutions.

推荐答案

海事组织,如果你想使你的测试易于运行,测试项目(S)绝对必须走在同一个解决方案的生产code 。而在另一种解决方案将测试可以正常工作,如果所有的开发人员都非常勤奋,它增加了改变生产code和运行测试的一个额外的障碍。我倾向于preFER删除尽可能多的障碍,尽可能。

IMO, if you want to make your tests easy to run, the test project(s) absolutely must go in the same solution as the production code. While putting tests in another solution may work if all developers are extremely diligent, it adds an extra barrier between changing production code and running the tests. I tend to prefer removing as many barriers as possible.

有几种不同的方式,你可以做到这一点。

There are a few different ways you can do it.

  • 在每一个解决方案的单一测试项目(Product.UnitTests.csproj)
  • 在每个系统中的一个测试项目(Product.SystemName.UnitTests.csproj)
  • 接着一个生产性项目和测试项目之一映射(Product.ProjectName.csproj和Product.ProjectName.Tests.csproj)

每个人都有自己的权衡,你必须权衡。

Each has its own trade-offs you have to weigh up.

每一个解决方案的单测试项目

有道理的,如果整个解决方案中包含有凝聚力的项目。如果你总是会使用相同的解决方案来开发,那么这是很好的有一个集中的测试项目。

Makes sense if the entire solution contains cohesive projects. If you are always going to be developing using the same solution, then it's nice to have a centralised test project.

这意味着有你的构建过程中减少开销(如果你有得分的项目,减少了装配计数解决方案还可以减少建造时间),并有维护一个.nunit文件或类似的开销。

It means there's a reduced overhead on your build process (when you have solutions with scores of projects, reducing the assembly count also reduces the build time) and there's no overhead of maintaining .nunit files or the like.

另外,大家都知道那里的测试去。缺点是,你必须通过命名空间来划分不同的生产项目,并测试一个项目,现在绑成别人。即这是最简单的一拿到买入的,因为欠保持跟踪和开发人员可以轻松地运行测试。不足之处是,在某些情况下,这不是一个很好的适合你开发的东西。

Also, everyone knows where the tests go. The downside is that you have to divide up different production projects by using namespaces, and the tests for one project are now tied into the others. I.e. this is the 'easiest' one to get buy-in for as there's less to keep track of and developers can easily run the tests. The downside is that in some cases this isn't a good fit for what you're developing.

每个系统的单测试项目

基本上与上述相同,除了它的更细粒度。您将相关项目纳入区域/系统,并使用一个单一的测试组件的每个。这增加了复杂性了一点,但也意味着系统更易于萃取/可重复使用的其他解决方案。

Basically the same as the above, except it's finer grained. You group related projects into areas / systems and use a single test assembly for each. This increases the complexity a little, but also means the systems are more easily extractable/re-usable in other solutions.

的生产项目和测试项目,一对一的映射

拥有最大的开销在创造新的组件方面,增加了生成时间有点当有项目加载并通常会使你的解决方案文件较大。需要勤奋始终保持一个.nunit项目文件的最新条款和不与-IDE单元测试发挥得这么好。

Has the most overhead in terms of creating new assemblies, increases the build times a bit when there's loads of projects and generally makes your solution file bigger. Requires diligence in terms of always keeping .nunit project files up to date and doesn't play so nicely with in-IDE unit testing.

向上,一面是保持一个测试项目,每一个生产项目意味着测试仅依赖于他们正在测试的功能(所以它更容易重新利用项目),你可以更轻松地检查$ C $通过运行一个项目在一个时间(而如果你运行所有的测试,你会得到更高的覆盖率,由于不相关的测试,有时可触到code,他们不感兴趣)C覆盖。此外,这是一个简单的规律可循,所以人们会明白的地方测试是为了去没有问题。

The up-side is that maintaining a test project for each production project means that the tests are only dependent on the functionality they're testing (so it's easier to re-use projects) and you can more easily check code coverage by running one project at a time (whereas if you run all of your tests, you will get higher coverage due to unrelated tests sometimes touching code they're not interested in). Furthermore, it's a simple pattern to follow, so people will understand where the tests are meant to go without a problem.

在总结:我认为以上任何可以很好地工作取决于你开发的东西,但如果你想一个解决方案,只是工作',那么我会倾向于去的一对一的映射。

In summary: I think any of the above can work well depending on what you're developing, but if you want a solution that 'just works', then I'd be inclined to go for the one to one mapping.

这篇关于你如何设置你的单元测试项目在.net(S)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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