Should Unit Tests be in their own project in a .Net Solution

自作多情 提交于 2019-11-30 08:11:58

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.

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).

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

I tend to have a specific test project/assembly per assembly. The test assembly will have the same name as the assembly it is supposed to test, with the addition of the .Test in the name and the namespace.

That way, you keep your tests isolated and they do not get deployed with your production code.

1 test project per solution with folders => regression/integration/unit which has subfolders that 'mirrors' your solution project/folder architecture.

Remember - tests ain't your production code. They should be separated.

Yes. Your unit tests should be a separate project, which compiles to its own DLL.

This means you're not deploying test code along with your project - and it encourages good design (since your tests can't see private/internal properties, you'll naturally tend towards testing those bits of your project which interact with other systems, rather than getting fixated on testing every detail of their internal implementation)

In terms of naming, we normally pick a "codename" for each project - current one's called Zanzibar - and then end up with projects like:

MyCompany.Zanzibar.Website (ASP.NET MVC web application)

MyCompany.Zanzibar.Website.Testing (contains unit tests for MVC web app)

Yes. Create a unit test project for each solution project.

There will only be a single executable. The units tests are held in a DLL.

Why not append 'UnitTests' to the relevant namespace.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!