简体   繁体   中英

One or more unit test projects for solution

I have a console app with two other class library projects -- totaling 3 projects -- in my solution.

I want to now add a unit test project. My question is do I add a "unit test project" per "regular project" in the solution or a single unit test project that can test all three?

In other words, if my projects are projA, projB and projC, do I add three unit test proejects eg projA.Tests, projB.Tests, etc. OR a single unit test project that can handle all three?

If the question is only Can a single unit test project that can handle all three? The answer is Yes but than to proceed next step I would say it depends. Personally, I tend to put all of the tests in a single project, with separate folders within the project for each assembly (plus further sub-folders as necessary.) This makes it easy to run the entire set within VisualStudio. If you have thousands of tests, a single project might prove too difficult to maintain. We usually split them out because we don't want to deploy them with our product. Whether you split them out per library or per solution there are merits to both.

Ultimately, you want tests to be immediately available to all developers, so that developers know where to find them when needed. You also want an obstacle free environment with minimal overhead to writing new tests. Tests must also compile and execute quickly - project structure can play a part in all of this.

You may also want to consider that different levels of testing are possible, such as tests for unit, integration or UI automation. Segregating these types of tests is possible in some tools by using test categories, but sometimes it's easier for execution or reporting if they are separate libraries.

In small projects where there aren't a lot of projects, a 1:1 ratio is usually the preferred approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM