Complete Guide to Unit Testing in .NET Core (NUnit and xUnit)

Video description

“Production application can break with a simple change that was unexpected to alter any other functionality.” Sounds familiar, right?

The good news is, with well-written unit tests, this would be a thing of the past.

Automated testing has been a buzzword for a while, but many times developers struggle to find a course that covers the fundamentals of unit testing while implementing what they learned in a real-world project! That is the focus of this course.

This course is all about writing effective unit tests using C# programming language and NUnit/xUnit as a unit testing framework. Along the way, you will learn the concepts related to unit testing. Today, unit testing is an absolutely required skill from any professional developer. Companies expect developers to know how to write unit tests using the best practices. This course will help you set up a solid foundation with a real-world example and how unit testing could be done in a .NET core web application with EF Core.

By the end of this course, you will have a solid foundation with unit testing. Along with a solid foundation, you will also implement what is learned in real-world N-Tier web applications with .NET 6 and EF Core.

What You Will Learn

  • Learn unit testing from scratch
  • Learn to set up and use the NUnit and xUnit test framework
  • Learn to set up and use the NUnit and xUnit test framework
  • Explore unit tests and how they are written
  • Run and debug unit tests
  • Implement unit testing in N-tier real-world web application project using xUnit

Audience

Implement unit testing in N-tier real-world web application project using xUnit

Basic knowledge of C# along with .NET Core and EF Core is required to gain the most out of this course. No prior experience is necessary in unit testing; you will learn it from scratch in this course.

About The Author

Bhrugen Patel: Bhrugen Patel is a passionate and creative software engineer with a strong focus on simplicity and thorough details. He has been programming since high school and was involved with multiple web and desktop projects using .NET. He has a master’s degree in computer science and a bachelor’s degree in computer engineering. He also has many years of experience with .NET C# and .NET MVC. He enjoys teaching alongside his full-time job.

Table of contents

  1. Chapter 1 : Introduction to the Course
    1. Welcome
    2. Manual Testing Overview
    3. Advantages of Automated Testing
    4. Tools Needed
    5. Types of Tests
    6. Testing Pyramid
    7. Logical Phase of an Automated Test
  2. Chapter 2 : First Unit Test
    1. .NET 6 Update - Nullable
    2. Create Project
    3. Create MSTest Project
    4. First Unit Test
    5. Failed Test Example
  3. Chapter 3 : Unit Testing
    1. Create NUnit Project
    2. First NUnit Test
    3. Debug and Assert
    4. Assignment 1 - Odd Number Checker
    5. Assignment 1 Solution - Odd Number Checker
    6. Assertion Model
    7. Testing multiple values
    8. Combine Unit Test with Expected Result
    9. Asserting Doubles
    10. Asserting String Values
    11. String Assert Helper Methods
    12. Asserting Null Values
    13. Global Initialization for Class
  4. Chapter 4 : NUnit Testing – Advance Concepts
    1. Asserting Collections
    2. Collections Helper Method
    3. Range Assert
    4. Multiple Assert
    5. Working with Exceptions
    6. Exceptions without Message
    7. Set Up Inheritance
    8. Assert Object Type
    9. Assignment 2 - Grading Calculator Part 1
    10. Assignment 2 - Grading Calculator Part 1 Solution
    11. Assignment 2 - Grading Calculator Part 2
    12. Assignment 2 - Grading Calculator Part 2 Solution
    13. Assignment 3 - Fibo Series
    14. Assignment 3 - Fibo Series Solution
  5. Chapter 5 : MOQ with Unit Testing
    1. Set Up Bank Account Class
    2. Setting Up Logger Class
    3. Integration Test Demo
    4. Unit Test with Fake Logger
    5. Mocking Overview
    6. MOQ in Action
    7. Missing MOQ
    8. Setting Up LogBook Withdrawal
    9. MOQ Setup with Conditional Return
    10. MOQ Setup Default Return Value
    11. MOQ Evaluate the Return Value
    12. MOQ and Out Parameters
    13. MOQ and Ref
    14. MOQ Default Return Values
    15. MOQ Properties
    16. MOQ Callbacks
    17. MOQ Verification
  6. Chapter 6 : xUnit
    1. Create xUnit Project
    2. xUnit Comparison
    3. xUnit Calculator Part 1
    4. xUnit Calculator Part 2
    5. Assignment 4 - Grading Calculator
    6. Assignment 4 - Grading Calculator xUnit Solution
    7. Assignment 5 - Fibo Series xUnit
    8. Assignment 5 - Fibo Series xUnit Solution
    9. MOQ and xUnit
    10. Customer xUnit
    11. Assignment 6 - Bank Account xUnit
  7. Chapter 7 : Real-World Example - NUnit
    1. Set Up Main Project
    2. Bongo Project Code Overview
    3. Bongo Models Date Checker Part 1
    4. Bongo Models Date Checker Part 2
    5. Set Up Data Access Unit Test Project
    6. In-Memory Database and Unit Testing
    7. Data Access Unit Tests
    8. Data Access Unit Tests Bugs and Pitfalls
    9. Set Up Bongo Core Unit Test Project
    10. Bongo Core MOQ Setup and GetAllBooking Test
    11. Bongo Core Exception Unit test
    12. Bongo Core Save Booking Setup
    13. Bongo Core Save Booking Unit Test
    14. Bongo Core Return Code TestCase
    15. Bongo Core Separating Unit Tests
    16. Bongo Web Test Project Setup
    17. Bongo Web Index Action Method Unit Test
    18. Bongo Web Checking View Name
    19. Bongo Web Controller Unit Tests

Product information

  • Title: Complete Guide to Unit Testing in .NET Core (NUnit and xUnit)
  • Author(s): Bhrugen Patel
  • Release date: October 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781803248660