Skip to content
0:00 / 0:00

#moq#xunit#unittesting

Mocking in C# Unit Tests - How To Test Data Access Code and More

IAmTimCorey

441K subscribers • 15 videos on Hallway

YouTube
  • Recommended by 4 people: 4 in engineering communities.
  • A classic. People kept recommending it from 2019 to 2022.
  • Presented by Tim Corey, software developer and educator

Intermediate. Assumes working knowledge.

309K views8 years ago4 recommendations

Tools and practiceProgramming languagesTestingC# and .NET

Tim Corey demonstrates how to use mocking to unit test C# code with external dependencies like databases.

Unit tests are great, but how do you test your data access? You sure don't want to actually delete records when you are testing the delete method, yet you definitely want to be sure the method is configured properly. This is the type of problem that stops a lot of developers from creating unit tests. In this video, I am going to show you how to overcome these obstacles in order to write tests that handle working with external dependencies like databases. Full courses: DevForge.com/ Source Code: DevForge.com/downloads/?code=MockingInUnitTests Patreon: patreon.com/IAmTimCorey Newsletter signup: signup.iamtimcorey.com/ Sponsors: Tuhafeni Angula (Patreon Subscriber) - Intro - Getting started: demo application code and setup - Problems with testing methods that manipulates with external stuff (database edits, e-mail senders etc) - Mocking explained - Writing tests with mocking - Adding references for testing with MOCK - Using statement - AutoMock.GetLoose() vs AutoMock.GetStrict(); - Using AutoMock: Writing the Unit Test with mocking - Refactoring method that's under a UnitTest - Checking data: comparing two objects - Testing method that returns void - Testing SQl call modification - Recap - Advice for beginners - What not to test and why - Summary - Learning steps - Concluding remarks

Why it's here

4 people recommend this

What people say. Recommended as a good primer for developers transitioning to unit testing and mocking in C#.

Moments people linked to

u/Saltypoisonin r/dotnet • Recommends

On “Need resources to learn deep dive into tdd and unit testing with xunit and moq”

A coworker sent me these a few months ago as we are transitioning into a TDD workflow. Definitely not a deep dive, but a good primer on the material and I'm sure the author has much more available. [video [video

u/r3ap4rin r/dotnet • Recommends

On “Are there any tutorials/courses on testing you would recommend?”

Tim Corey has a good starter video on unit testing, starting off simple and advancing to more in depth testing of methods and exceptions. [video A good follow-up video for mocking tests is also available from him: [video

u/imp4l3rin r/dotnet • Recommends

On “How to efficiently Unit Test .net core WebApps?”

…o not need DI for unit tests of course. However, OP's question was related to aspnet applications, where there are often dependencies to classes, services and so on. In my experience then the absolute best way of learning to do something is by doing it. Practice makes perfect. These videos will get you started understanding the principles: \- [video \- [video \- [video An example:Imagine you have some controller that takes as parameters in its constructor (dependency injection) public controller(ILogger logger, IService service) Tests public class UnitTest1 { public interface IService // Usually this interface is implemented in the application layer…
2View on Reddit

u/tokinblin r/dotnet • Recommends

On “Seeking advice: Should I use in memory database to test an horrible codebase?”

Came across this when I was looking for something similar link to this video