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

前端 未结 5 1635
攒了一身酷
攒了一身酷 2020-12-31 00:52

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

相关标签:
5条回答
  • 2020-12-31 01:38

    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.

    0 讨论(0)
  • 2020-12-31 01:40

    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.

    0 讨论(0)
  • 2020-12-31 01:45

    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)

    0 讨论(0)
  • 2020-12-31 01:52

    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.

    0 讨论(0)
  • 2020-12-31 01:53

    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.

    0 讨论(0)
提交回复
热议问题