如果单元测试是在他们自己的项目在.NET解决方案 [英] Should Unit Tests be in their own project in a .Net Solution

查看:156
本文介绍了如果单元测试是在他们自己的项目在.NET解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该开始为我的单元测试一个新的项目?这将意味着我会得到两个可执行文件是否正确?然后,我很担心命名空间组织。我将能够把单元测试在同一个命名空间作为他们正在测试,虽然它们是不同项目的一部分类?

Should I start a new project for my unit tests? That would mean that I would get two executables correct? Then I am worried about the namespace organization. Would I be able to put the unit test in the same namespaces as the classes that they are testing although they are part of a different project?

这引出了另外一个问题。我知道的命名空间命名约定是CompanyName.TechnologyName.Feautre.Design。我将如何得到这个权利在我的解决方案/项目布局?解决方案是否NAME =公司名称,项目名称=技术叫什么名字?

This raises another question. I know that namespace naming convention is CompanyName.TechnologyName.Feautre.Design. How would I get this right in my solution/project layout? Does the solution name = companyname, project name = technology name?

如果是这样的话是否意味着我不能分开我的单元测试到一个新的项目。

If that is the case does that mean I can't separate my unit tests into a new project.

推荐答案

最好的办法是让每个生产项目单独的单元测试项目。这确保您可以有所不同,各地对移动它们。

The best approach is to have a separate unit test project per 'production project'. This ensures that you can vary and move them around in pairs.

如果你有一个单元测试项目涵盖了多个目标的项目,这将创建一个人工紧这两个项目之间的耦合的,因为你将不能够没有所有的编译单元测试项目它的目标项目。这又使得它真的很难单独测试一个项目 - 这是单元测试是所有关于

If you have one unit test project covering more than one target project, this creates an artificial tight coupling between these two projects, because you will not be able to compile the unit test project without all of its target projects. This, again, makes it really hard to test a single project in isolation - which is what unit testing is all about.

这是非常重要的是保持在单独的库单元测试,因为这可以确保您测试仅在公共API 您code(黑盒测试)。

It's very important to keep unit tests in separate libraries, because this ensures that you test only the public API of your code (black box testing).

我的目标命名空间之后追加的UnitTest的名字我的名字空间。

I name my namespaces by appending "UnitTest" after the target namespace.

这篇关于如果单元测试是在他们自己的项目在.NET解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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