We may earn an affiliate commission when you visit our partners.
Course image
Udemy logo

Master .NET and C# Unit Testing with NUnit and Moq

Dmitri Nesteruk

The goal of this course is to teach you Unit Testing and the use of the latest and greatest tools and frameworks available on the market today. This course covers the following technologies:

Read more

The goal of this course is to teach you Unit Testing and the use of the latest and greatest tools and frameworks available on the market today. This course covers the following technologies:

  • NUnit, the most popular unit test framework available for .NET
  • Moq, a mocking framework
  • dotMemoryUnit, a unit test framework for testing memory consumption
  • ReSharper (its unit test runner) used extensively in this course
  • dotCover is used to illustrate the concepts of code coverage and continuout testing

In this course you'll learn what unit tests are, how to write and execute them, what are fakes/mocks/stubs/moles and how to use a mocking framework.

Enroll now

What's inside

Learning objectives

  • What unit tests are for and how they are written
  • How to set up and use the nunit test framework
  • What are the different test doubles: fakes, stubs, mocks
  • How to effectively use the moq mocking framework
  • How to use the resharper unit test runner
  • How to write memory-related unit tests using dotmemoryunit

Syllabus

Introduction
Learn to use the most popular .NET unit testing framework

An overview of the things we're going to learn in this section of the course.

Read more

What exactly is unit testing and why do we need it? Also, what is TDD?

Setting Up a Unit Testing Project
Unit Test Runners: Standalone, VS, R#/Rider
Bank Account Scenario

A summary of the things we've learned in this section of the course.

Learn about NUnit's various assertion classes and methods

An overview of the things we'll meet in this section of the course.

Basic Assertions and Possible Test Results

More information about ways of issuing warnings in unit tests.

Arrange Act Assert
Multiple Assertions
Exceptions

A summary of all the things we've learned in this section of the course.

Learn some of the popular approaches to the way testing is done

An overview of different approaches to unit testing.

If you need to run a single unit test on several different sets of data, you can do so using the [TestCase] attribute. ReSharper, Rider and other tools support the running of test cases individually or collectively.

Code coverage tools give you information about the percentage of your code that is actually covered by your tests. Higher values are obviously better, but having 100% coverage is typically a goal not worth going for... unless you have a lot of time on your hands.

Continuous testing means that instead of running tests when you want them to run, you run them on every save or on every compile. Of course, the test runner needs to be smart enough to rerun only affected tests, not every single test that you have in your system.

Control your app's memory consumption with JetBrains' free memory unit testing framework.

Learn how to hand-roll simple test doubles.

An overview of the lectures in this section of the course. Also, source code is attached here!

A discussion of why test doubles are required, and some of the varieties: mocks, stubs and fakes.

A re-worked BankAccount scenario which gets a second component in as a dependency. Oh no, what do we do now?!

Let's build a simple fake object. Nothing to it, really, provided you have an interface you can implement.

A rather advanced approach to building fakes at runtime by defining a DynamicObject that can conform to any interface you might need.

Fakes are great, but if you depend on the behavior of a dependent object for correct operation, what then? We still need to fake it, but the results may need to be different depending on the tests. Stubs to the rescue!

A more powerful incarnation of subs, mocks allow us to do many things, including testing the number of calls of a test double's method. Mocks are typically made through mock frameworks, but we'll roll a simple one ourselves.

A summary of all the things we've learned in this module.

Learn about mocking and the Moq framework

An overview of this, rather large, section of the course that deals with Moq, a mocking framework.

We return to our scenario of a bank account depending on logging and see how we can solve this problem once and for all using the Moq library.

We look at how to mock methods of an object, including an ability to specify particular return values dependent upon the input arguments.

You can direct mock methods to return values which are dependent upon the arguments passed into those methods.

It's also possible to mock methods that have ref or out parameters, sometimes with surprising results.

We look at a few more sophisticated concepts of method mocking, including an ability to provide a functioning method body as well as what happens if you want to mock exception throwing.

Having spent lots of time learning how to mock methods (their arguments and return values), we now turn to properties, which are much simpler.

A mock object's properties, by default, do not behave as properties: instead, they are no-op constructs. But what if you want them to behave like real properties, storing values and yielding them in setters? Well, Moq makes this possible (and easy).

Having figured out methods and properties, we now turn to events: both those based on the typical sender-args arrangement as well as events constructed with custom delegates.

Callbacks allow you to specify custom pieces of code to be invoked whenever some part of a mock object is being accessed. Useful for tracing and ad-hoc profiling.

Verification lets us check that a particular part of a mock object was, in fact, accessed a specific number of times.

Here we look at a few examples of customizing the behavior of mock objects.

If you decide to mock protected members, you need to use a slightly different interface. One unpleasant side effect is that, since those members are protected, you cannot feed their names via either Expression<T> or nameof. The end result is that, unfortunately, those have to be specified as strings, with all the associated performance implications.

A summary of the myriad of things that we've learned in this section of the course.

Course summary and links to other courses

A summary of all the things we've learned in this course.

Links to my other courses!

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Taught by Dmitri Nesteruk, who is recognized for their work in .NET unit testing
Explores NUnit, a popular unit testing framework in the .NET industry
Develops skills in using Moq, dotMemoryUnit, and ReSharper, which are commonly used tools in unit testing
Teaches learners how to effectively write and execute unit tests
Examines concepts of code coverage and continuous testing, which are highly relevant to unit testing in industry
Provides guidance on best practices for unit testing, which helps learners strengthen their skills

Save this course

Save Master .NET and C# Unit Testing with NUnit and Moq to your list so you can find it easily later:
Save

Reviews summary

In-depth unit testing course

According to students, this course is a great course if you're interested in learning unit testing in .NET and C#. Learners say it's well-structured and engaging.
The course is engaging.
"I found the course to be very engaging."
The course is well-structured.
"The course is very well-structured."

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Master .NET and C# Unit Testing with NUnit and Moq with these activities:
Review Unit Testing Concepts
Prepare for the course by refreshing your knowledge of fundamental unit testing concepts.
Browse courses on Unit Testing
Show steps
  • Review course notes or materials from previous courses.
  • Reread key articles or books on unit testing.
Follow Online Tutorials on Unit Testing Best Practices
Enhance your knowledge by following guided tutorials that provide best practices for effective unit testing.
Browse courses on Unit Testing
Show steps
  • Identify reputable tutorials on unit testing best practices.
  • Follow the tutorials and implement the recommended practices.
Practice Unit Testing with Exercises
Reinforce your understanding of unit testing by completing hands-on exercises.
Browse courses on Unit Testing
Show steps
  • Set up a unit testing project and run sample tests.
  • Practice writing test cases for different scenarios.
  • Test your code for memory leaks using dotMemoryUnit.
Three other activities
Expand to see all activities and additional details
Show all six activities
Participate in a Unit Testing Hackathon
Put your skills to the test and collaborate with others in a competitive unit testing environment.
Browse courses on Unit Testing
Show steps
  • Find a relevant unit testing hackathon.
  • Form or join a team to participate.
Attend a Workshop on Advanced Unit Testing Techniques
Gain practical experience and insights by attending a workshop focused on advanced unit testing techniques.
Show steps
  • Research and identify a relevant workshop.
  • Register and attend the workshop.
  • Apply the techniques learned in your own projects.
Contribute to an Open-Source Unit Testing Framework
Contribute to the development and maintenance of a popular unit testing framework.
Browse courses on Open Source
Show steps
  • Choose a unit testing framework to contribute to.
  • Identify an area where you can make a valuable contribution.
  • Submit a pull request with your changes.

Career center

Learners who complete Master .NET and C# Unit Testing with NUnit and Moq will develop knowledge and skills that may be useful to these careers:
Unit Test Engineer
Unit Test Engineers are responsible for writing and running tests that verify the behavior of software applications. This course can help you develop the skills and knowledge necessary to write effective unit tests. You will learn about different types of unit tests, how to set up and use a unit testing framework, and how to interpret the results of unit tests. This course will also help you develop a solid understanding of the fundamentals of unit testing, which will be essential for success as a Unit Test Engineer.
Software Test Analyst
Software Test Analysts are responsible for planning, executing, and evaluating software testing activities. This course can help you develop the skills and knowledge necessary to become a successful Software Test Analyst. You will learn about different types of software testing, how to develop test plans, and how to analyze the results of software testing. This course will also help you develop a solid understanding of the fundamentals of software testing, which will be essential for success as a Software Test Analyst.
Quality Assurance Analyst
Quality Assurance Analysts are responsible for ensuring that software applications meet the required quality standards. This course can help you develop the skills and knowledge necessary to become a successful Quality Assurance Analyst. You will learn about different quality assurance techniques, how to develop quality assurance plans, and how to evaluate the results of quality assurance testing. This course will also help you develop a solid understanding of the fundamentals of quality assurance, which will be essential for success as a Quality Assurance Analyst.
Software Developer
Software Developers design, develop, and maintain software applications. This course can help you develop the skills and knowledge necessary to become a successful Software Developer. You will learn about different programming languages, how to design and implement software applications, and how to test and debug software applications. This course will also help you develop a solid understanding of the fundamentals of software development, which will be essential for success as a Software Developer.
Project Manager
Project Managers are responsible for planning, executing, and controlling software development projects. This course can help you develop the skills and knowledge necessary to become a successful Project Manager. You will learn about different project management methodologies, how to develop project plans, and how to manage project teams. This course will also help you develop a solid understanding of the fundamentals of project management, which will be essential for success as a Project Manager.
Business Analyst
Business Analysts are responsible for understanding business needs and translating them into technical requirements. This course can help you develop the skills and knowledge necessary to become a successful Business Analyst. You will learn about different business analysis techniques, how to develop business analysis requirements, and how to evaluate business analysis proposals. This course will also help you develop a solid understanding of the fundamentals of business analysis, which will be essential for success as a Business Analyst.
Systems Analyst
Systems Analysts are responsible for studying, analyzing, and designing computer systems. This course can help you develop the skills and knowledge necessary to become a successful Systems Analyst. You will learn about different systems analysis techniques, how to develop systems analysis requirements, and how to evaluate systems analysis proposals. This course will also help you develop a solid understanding of the fundamentals of systems analysis, which will be essential for success as a Systems Analyst.
Software Tester
Software Testers are responsible for testing software applications to find and fix bugs. This course can help you develop the skills and knowledge necessary to become a successful Software Tester. You will learn about different software testing methods, how to develop software test plans, and how to execute and evaluate software tests. This course will also help you develop a solid understanding of the fundamentals of software testing, which will be essential for success as a Software Tester.
Technical Writer
Technical Writers are responsible for creating and maintaining technical documentation. This course can help you develop the skills and knowledge necessary to become a successful Technical Writer. You will learn about different technical writing styles, how to organize and structure technical documents, and how to write effective technical documents. This course will also help you develop a solid understanding of the fundamentals of technical writing, which will be essential for success as a Technical Writer.
Information Security Analyst
Information Security Analysts are responsible for protecting computer systems from unauthorized access, use, disclosure, disruption, modification, or destruction. This course may be useful in developing the skills and knowledge necessary to become an Information Security Analyst. You will learn about different information security threats, how to develop information security policies and procedures, and how to implement information security controls. This course will also help you develop a solid understanding of the fundamentals of information security, which will be essential for success as an Information Security Analyst.
Computer Network Architect
Computer Network Architects are responsible for designing, implementing, and maintaining computer networks. This course may be useful in developing the skills and knowledge necessary to become a Computer Network Architect. You will learn about different computer network architectures, how to design and implement computer networks, and how to maintain computer networks. This course will also help you develop a solid understanding of the fundamentals of computer networking, which will be essential for success as a Computer Network Architect.
Database Administrator
Database Administrators are responsible for managing and maintaining databases. This course may be useful in developing the skills and knowledge necessary to become a Database Administrator. You will learn about different database management systems, how to design and implement databases, and how to maintain databases. This course will also help you develop a solid understanding of the fundamentals of database management, which will be essential for success as a Database Administrator.
Data Analyst
Data Analysts are responsible for collecting, cleaning, and analyzing data to find patterns and trends. This course may be useful in developing the skills and knowledge necessary to become a Data Analyst. You will learn about different data analysis techniques, how to use data analysis tools, and how to interpret data analysis results. This course will also help you develop a solid understanding of the fundamentals of data analysis, which will be essential for success as a Data Analyst.
Web Developer
Web Developers are responsible for designing, developing, and maintaining websites. This course may be useful in developing the skills and knowledge necessary to become a Web Developer. You will learn about different web development technologies, how to design and implement websites, and how to maintain websites. This course will also help you develop a solid understanding of the fundamentals of web development, which will be essential for success as a Web Developer.
IT Manager
IT Managers are responsible for planning, directing, and coordinating the activities of an IT organization. This course may be useful in developing the skills and knowledge necessary to become an IT Manager. You will learn about different IT management techniques, how to develop IT management plans, and how to implement IT management strategies. This course will also help you develop a solid understanding of the fundamentals of IT management, which will be essential for success as an IT Manager.

Reading list

We've selected 11 books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Master .NET and C# Unit Testing with NUnit and Moq.
Provides a comprehensive overview of unit testing principles, practices, and patterns. It covers topics such as test-driven development (TDD), mocking, and continuous integration.
Practical guide to unit testing. It covers topics such as test design, test automation, and test maintenance.
Classic in the field of software design. It covers topics such as refactoring techniques, design patterns, and code smells.
Popular introduction to design patterns. It covers topics such as design patterns, object-oriented programming, and software architecture.
Collection of essays on the topic of software development. It covers topics such as software design, software testing, and software maintenance.
Classic in the field of software engineering. It covers topics such as software development management, software project management, and software risk management.
Classic in the field of software development management. It covers topics such as software team management, software project management, and software development culture.
Classic in the field of software development. It covers topics such as the psychology of software development, the sociology of software development, and the economics of software development.
Classic in the field of software development. It covers topics such as software design, software testing, and software maintenance.

Share

Help others find this course page by sharing it with your friends and followers:
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2024 OpenCourser