© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
14 replies
AFC

✅ Testing Guidance (Unit/Integration)

Hello! I am having the worst time trying to wrap my head around how/what/when to do unit tests vs integration tests. My company currently has no testing setup and so I am being tasked with adding it to one of our web apis we are currently rewriting.

The part I am mainly struggling on is where the db comes into play. We have an IUnitOfWork interface that's currently only exposing
Set<T>
Set<T>
Query<T>
Query<T>
(which is just Set<T> with AsNoTracking enabled) and
SaveChanges
SaveChanges
on the DbContext. That's injected pretty much everywhere we need to make a database query, so most of our services have it injected. This was a pattern set before I joined the company and we've just followed it since.

With that said, if I wanted to unit test one of those services that have a dependency on IUnitOfWork, it doesn't seem like I could easily mock this since it's generic and reliant on ef core. What should I do in this scenario? Just integration test it? Inject the concrete DbContext and try and mock the DbSets? Abstract away the "repository" (that seems overkill just to have testing) using the repository pattern on top of ef core?

The loose definitions of the different testing approaches has been driving me insane while trying to figure out how to set all this up. Would I hybrid approach work or is it not recommended? For example if I wanted to test a particular service that is dependent on the db should I spin up the db in a test container and run the test? From what I can tell the integration tests use WebApplicationFactory to call an endpoint to test instead of testing a particular service.

I think I am just caught up in the purity of the whole thing. Any guidance would be greatly appreciated
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

unit testing
C#CC# / help
2y ago
Unit testing
C#CC# / help
2y ago
✅ Unit testing
C#CC# / help
3y ago
Unit/Integration testing - what are good approaches?
C#CC# / help
2y ago