Unit Testing for C# Developers (Udemy.com)

Master unit testing C# code with NUnit and Moq: all about dependency injection, best practices and pitfalls to avoid

Created by: Mosh Hamedani

Produced in 2018

What you will learn

  • Learn unit testing from scratch
  • Tips and tricks to write clean, maintainable and trustworthy tests
  • Write loosely-coupled and testable code
  • Refactor legacy code towards testable code
  • Understand and implement dependency injection
  • Use mocks to isolate code from external dependencies
  • Apply the unit testing best practices
  • Learn the anti-patterns to avoid

Quality Score

Content Quality
Video Quality
Qualified Instructor
Course Pace
Course Depth & Coverage

Overall Score : 92 / 100

Live Chat with CourseDuck's Co-Founder for Help

Need help deciding on a software testing course? Or looking for more detail on Mosh Hamedani's Unit Testing for C# Developers? Feel free to chat below.
Join CourseDuck's Online Learning Discord Community

Course Description

Picture this: you make a simple change to the code and suddenly realize that you created a dozen unexpected bugs. Sound familiar? You're not alone!
Good news is, unit testing can make this a thing of the past.
Maybe you've heard of automated or unit testing before and you're keen to learn more.
Or perhaps you've tried to learn it and got a bit lost or ended up with fat and fragile tests that got in the way and slowed you down.
Either way, what you need is a course that will teach you all you need to know about this essential skill - from the basics, right through to mastery level.

What is unit testing?
In a nutshell: it's the practice of writing code to test your code and then run those tests in an automated fashion.

Why learn unit testing?
Why write extra code? Wouldn't that take extra time to write? Would that slow you down? Why not just run the application and test it like an end user?
Thinking like this is the mistake lots of people make. I used to make it myself. I've had to learn the hard way!
I learned pretty fast that if you're building a complex application or working on a legacy app, manually testing all the various functions is tedious and takes a significant amount of time.

As your application grows, the cost of manual testing grows exponentially. And you're never 100% sure if you've fully tested all the edge cases. You're never confident that your code really works until you release your software and get a call from your boss or an end user!
Several studies have shown that the later a bug is caught in the software development lifecycle, the more costly it is to the business.
Automated tests help you to catch bugs earlier in the software development lifecycle, right when you're coding. These tests are repeatable. Write them once and run them over and over.

The benefits of using unit tests are:
  • help you to catch and fix bugs earlier, before releasing your app into production
  • help you to write better code with less bugs
  • help you to produce software with better design - extensible and loosely-coupled
  • give you rapid feedback and tell you if your code *really* works
  • force you to think of edge cases that you didn't realize existed
  • test your code much faster
  • tell if you have broken any functionality as you write new code
  • allow you to refactor your code with confidence
  • act as documentation about what your code does
  • save you both time and money

A valuable skill for senior developers
More and more companies are recognizing the advantages of automated testing, that's why it's a must-have for senior coders. If you're looking to reach the higher levels in your coding career, this course can help.
You don't need any prior knowledge of automated testing. You only need 3 months of experience programming in C#.

With this course you'll learn:
  • senior coder secrets - best practices to write great unit tests
  • tips and tricks to keep your tests clean, trustworthy and maintainable
  • the pitfalls to avoid anti-patterns
  • how to refactor legacy, untestable code into loosely-coupled and testable code
  • all about dependency injection the one thing every coder needs to know
  • the power of mocks when and how to use them and when to avoid

You'll get:
  • 6 hours of HD video
  • tutorials and guidance from a senior coder with 15+ years' experience
  • exercises with step-by-step solution
  • downloadable source code
  • lifetime access
  • access online or offline at any time on any device
  • certificate of completion to present to your current or prospective employer
Who this course is for:
  • Anyone who wants to build better quality software with fewer bugs
  • Any developers who want to transition to the senior level

*Some courses are excluded from this sale. Coupon not working? If the link above doesn't drop prices, clear the cookies in your browser and then click this link here.
Also, you may need to apply the coupon code directly on the cart page to get the discount.

Coupon Code

Instructor Details

Mosh Hamedani

Hi! My name is Mosh (Moshfegh) Hamedani! I'm a passionate software engineer with two decades of experience and I've taught over 3 million people who to code or how to become professional software engineers through my YouTube channel and online courses.
My goal is to make software engineering fun and accessible to everyone. That's why my courses are simple, pragmatic and free of BS.



100 total reviews

5 star 4 star 3 star 2 star 1 star
% Complete
% Complete
% Complete
% Complete
% Complete

By Vinicius Uemura on 2 weeks ago

I have taken other unit tests courses here at Udemy and this one from Mosh is by far the best one. Concepts well explained, good content and practical examples to apply with real life scenarios. Really enjoyed it.

By Camp Horton on 3 weeks ago

I can't imagine a better course on unit testing. All concepts are well explained and it's loaded with practical exercises. My CompSci program back in college covered testing in only one class session and all we did was test a few sorting algorithms. Completely useless. I'm so grateful this course could fill that gap.

By Ceren An?l on a month ago

That is really educational course, thank you so much Mosh. In the content, there are enough examples :) I learnt too many things in this course. I recommended.

By Marc Ziss on 2 months ago

Nice real world, examples! Mosh does a very good job explaining the details of what to test and what not to as well as why.The only cons I have to a strong pro review is that there is a Q+A section for the course that goes ignored ( I'm assuming Mosh wants other students to answer, which hasn't really happened) and also there is a strong reliance on Jet Brains tooling which are not free (but good tools nonetheless)

By Van Cong Minh on 3 months ago

This course is absolutely awesome. It builds the foundation of unit testing and provides some techniques along with interesting examples. It is easy to follow. This course may require the understanding of lambda expression for delay evaluation which is used in Returns method from Moq framework.

By J-Richardson on a month ago

This is good information. I have learned a lot about how to do unit testing. The problems I am having with implementing unit testing at my workplace are:(1) Only about half of the code we use is in C#, the other half is in C/C++. Will all of these concepts also work for these files.(2) We have massive amounts of legacy code that does not break things out in a way to do interfaces. This would be a major undertaking to make the code work this way and may not be worth the additional cost. There is also a lot of overhead when implementing code using interfaces and it may add additional time/resources to the work.(3) In this training there is a lot of modification to the existing (production) code. Although this seems to make the existing code more readable and better, any modification can also introduce new bugs. It would be best to first be able to test the existing code "as is" prior to any modifications. The training uses Mock objects to do the testing and since there is no way to tests without the Mock objects, the code "as is" is untestable, thus it is not possible to do testing on the legacy code we already have. :(

By Colin Powell on 2 months ago

Excellent course tried many other courses on unit tests but couldnt get the exact concept to get going. After this course I feel i have a great foundation to go forwards. Look forward to a Test Driven Development course by the same author. The main reason I understood from this course was not just because of clear explanations but because it takes you forward in gradual steps. If you prefer this learning style then this course is for you.

By Subhi Hamidi on 3 weeks ago

This is my 4th course with Mosh, I really like the useful content the good trick that He told me. I have studied C# at University for more than 450 hours, yet these C# courses taught me way more things. I really like it and if there were more stars I would still give them.

By Ryszard Wo?niak on 4 months ago

The course is really good, especially the topics that cover the Dependency Injection and Moq Framework, but in the Resources folder, there is missing the last example with HouseKeeper class. It prevented me from fully understood this exercise.

By Arturo Monroy on 2 weeks ago

Me parece bueno el curso, lo recomiendo.La parte final del mismo, no esta y por eso pongo 3.5 estrellas

By Jason Plank on a month ago

I really enjoyed this course. Was challenging and informative

By Daniel Terceros on 2 months ago

Excellent explanation, examples and exercises. Looking forward to see more courses from you. Appreciate it