Should I add the nupkg dependencies of the Assembly of the SUT to the Test Project as well?

15 views Asked by At

I'm relatively new to writing unit tests. I ran into this scenario while writing unit test cases in .NET 8,for azure functions.

  • Project 1 - ABC.Functions
  • Project 2 - ABC.Functions.Test

I have added a few nuget packages related to Azure functions in Project1. Should I be replicating these references in Project2 as well? Even if I wanna create mocks while Unit testing the SUT I still need the references to these nuget packages. Are there any design flaws in my test? Is that why I'm having to rely on the nuget package? Or is it completely normal to refer nuget package dependencies of SUT assembly in Test Project.

I haven't tried anything in particular as I wasn't pretty sure where the flaw was or if it is even flawed in the first place.

1

There are 1 answers

0
Mark Seemann On

Add the dependencies as needed. The compiler and/or IDE will tell you if the test project also needs the dependencies.

Typically, if you're only using and referencing the SUT from the test project, the test code isn't going to need the SUT's dependencies (they're still there, transitively). If, on the other hand, you also need to create some objects of types defined in those NuGet packages, then you'll also need to add those dependencies to your test project.