Reputation: 879
I currently have a solution setup with two projects:
MySolution
- MyClassLibrary
- MyClassLibrary.Tests
The MyClassLibrary project is distributed as a NuGet package. The Tests project contains all of my unit tests which are not currently distributed with the NuGet package.
The problem is that inside of MyClassLibrary, one of my classes accepts an IMyRepository as a constructor parameter (to allow dependency injection). I then have an abstract test class setup in the MyClassLibrary.Tests project called IMyRepositoryTests. The intention is that when you write your own implementation of IMyRepository, you can write a test class that simply inherits from IMyRepositoryTests and pass in an instance of your concrete class and all the tests will be done for you.
So the structure looks like this:
Solution
- MyClassLibrary
-- MyServiceClass(IMyRepository repository)
-- IMyRepository
- MyClassLibrary.Tests
-- MySericeClassTests
-- IMyRepostoryTests (abstract)
The problem is that the Tests project doesn't get distributed with the NuGet package, so if someone wants to unit test their concrete implementation of IMyRepository, they will have to write all of their own tests which (1) will not take advantage of the test code I've already written for them and (2) may not conform to the specifications I intended for IMyRepository.
If I move IMyRepositoryTests to the MyClassLibrary project, then that project will have dependencies on my unit testing frameworks (Xunit and Moq). This adds unnecessary dependencies for someone who is not doing unit testing.
If I ship the Tests project with the NuGet package, then I create the same issue, plus it doesn't seem like standard practice to ship NuGet packages with their unit tests.
I could ship the Tests project as a separate NuGet package but that seems strange as well.
Are there any other options that I am missing?
Upvotes: 2
Views: 988
Reputation: 8562
Create a separate package for your test assembly. You'll want to do this as your end users won't want to include it in their main app, which is what will happen if you put your test assembly in with your main assembly.
Upvotes: 5