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

前端 未结 5 1705
攒了一身酷
攒了一身酷 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: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)

提交回复
热议问题