Skip to content
0:00 / 0:00

#nsubstitute#unittesting#mocking

Clean mocking for unit tests using NSubstitute in .NET (Core, Framework, Standard)

Nick Chapsas

429K subscribers • 62 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Nick Chapsas

Beginner. No background in the topic needed.

46K views6 years ago2 recommendations

Tools and practiceTestingC# and .NET

Nick Chapsas demonstrates how to get started with mocking external dependencies in unit tests using NSubstitute.

Become a Patreon and get source code access: patreon.com/nickchapsas Check out my courses: dometrain.com The giveaway is now over. Thanks for participating. Hello everybody I'm Nick and in this .NET tutorial I will show you how you can get started with mocking external dependencies in unit testing using NSubstitute. NSubstitute is, in my opinion, the best mocking framework for unit tests in .NET and I highly recommend it. NSubstitute detailed documentation: nsubstitute.github.io/help/getting-started/ In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways, most often as part of a software testing initiative. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts. Don't forget to comment, like and subscribe :) Social Media: Follow me on GitHub: bit.ly/ChapsasGitHub Follow me on Twitter: bit.ly/ChapsasTwitter Connect on LinkedIn: bit.ly/ChapsasLinkedIn #dotnet #tests #mocking

Why it's here

2 people recommend this

What people say. Recommended as a great starting point for learning how to mock dependencies in .NET unit tests.

u/Elfocrashin r/dotnet • Recommends

Clean mocking for unit tests using NSubstitute in .NET

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…