From the course: C# Test-Driven Development
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Introduction to mocking - C# Tutorial
From the course: C# Test-Driven Development
Introduction to mocking
- [Instructor] More often than not, the system under test has dependencies and those dependencies may have their own unit tests. Therefore we do not want to test the dependencies we want to test our system under test. But what do we do when those dependencies have functionality that we don't really need to run because we trust those dependencies? For instance, when we have a database and do not want to write to the database as part of our test of our own system under test. In that case, we might consider using so-called test doubles. So we have specific objects that can behave like the dependency but are not the dependency. There are different kinds of that. The first and probably most well-known term is that of a mock. A mock handles so-called indirect outputs of the system under test. So, it's an object with properties and with methods and they implemented and so among other things, the mock knows which methods were called, how often they were called, et cetera, et cetera. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Introduction to mocking3m 18s
-
Adding an interface3m 6s
-
(Locked)
Using a test with a mock6m 14s
-
(Locked)
Testing without a database: Preparations3m 21s
-
(Locked)
Demo: Testing without a database6m 1s
-
(Locked)
Testing ASP.NET Core applications: Preparations2m 11s
-
Demo: Testing ASP.NET Core applications4m 23s
-
(Locked)
Challenge: Testing an API2m 13s
-
(Locked)
Solution: Testing an API5m 27s
-
(Locked)
-