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 e.g. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With