
Discover automated testing concepts and practice unit testing with NUnit and xUnit on a real-world .NET Core project using Entity Framework Core.
Learn automated testing by writing test code that runs against your application to verify behavior in unit testing, contrasting it with manual testing that requires launching app and verifying logic.
Discover why automated testing matters, as tests written once can run anytime and on demand. Catch bugs before deployment and gain reliability and confidence when deploying to other environments.
Explore the essential tools for this course, including dotnet 6, Visual Studio 2022, and SQL Server 2019, with options to use dotnet 5 and Visual Studio 2019 if needed.
Access project resources, download the course content with needed snippets in section four and the application in section seven, and visit Dotnet mastery and GitHub for comments to replicate changes.
Explore three test types in automated testing: unit tests, integration tests, and user interface tests. Understand their depth, scope, external dependencies, execution speed, and brittleness to choose appropriate coverage.
The testing pyramid prioritizes unit, integration, and UI tests, with unit tests the largest and fastest, while UI tests cover the happy path and errors are tested in unit tests.
Explore the triple-a pattern in automated testing by detailing arrange, act, and assert phases, practicing how to write and run your first unit test.
Create an empty Visual Studio 2022 solution named Sparky, add a C# class library Sparky, and set the .NET Core version to dotnet five or six for unit testing.
Create an MSTest project for the Sparky solution, set up .NET 6, and configure the Microsoft.NET Test SDK, MSTest framework, and test adapter for unit testing a class library.
Write your first unit test using mstest, following arrange, act, and assert to test the calculator's add numbers with 10 and 20 and expect 30.
Demonstrate net core unit testing with NUnit and XUnit by showing a failing test when results differ, then restoring a passing test, and always placing expected before actual.
Explore switching from MsTest to NUnit and XUnit, create a new NUnit-based class library project named Sparky.UnitTest, and install NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk to enable test discovery in Visual Studio.
Set the same namespace for the Sparky main project and its unit tests, then create your first NUnit test using TestFixture and Test, following arrange, act, and assert.
Explore the arrange, act, and assert phases of a .NET unit test by testing a calculator’s add method using Assert.AreEqual. Learn to run and debug tests with breakpoints for analysis.
Add a boolean odd-number checker method to the calculator class. Create two unit tests: odd input returns true, even input returns false, using NUnit or XUnit in .NET Core.
Implement unit tests for the calculator's is odd method using arrange, act, and assert, verifying even inputs return false and odd inputs return true.
Compare classic and constraint-based assertion models in unit testing for .NET core, using assert that with the Is class to verify true, false, and equality.
Parameterize a .NET Core unit test with the test case attribute to run multiple values, like 11 and 13, without repetition.
Combine unit tests with expected results in a single test case that checks odd numbers and returns true for odd and false for even.
Learn how to test doubles in .NET Core unit tests using NUnit, implementing an add numbers double method, and using delta to compare floating-point values across cases.
Demonstrate testing string values by building a customer class with a combine names method using string interpolation for first and last name, and validate the name with a unit test.
Master string assertion helpers in .NET unit testing with NUnit and XUnit. Use equality checks, containment, starts with, ends with, ignore case, and regex matches to validate output strings.
Add a greet message property to a customer and demonstrate asserting null values in unit tests using arrange, is null, and greet logic.
Use a global setup method with a setup attribute to initialize a shared customer object for all tests, removing duplicated code.
Explore asserting values in a collection by generating an odd range of integers between min and max, and validating results with unit test assertions.
Explore collection helper methods in unit testing for .net core with nunit and xunit, including equality, contains, count, is ordered, and is unique.
Demonstrate using range assertions in NUnit to verify a customer discount stays within 10 to 25 percent, testing default and bumped discounts and proving a 35 percent value fails.
Discover how to use assert.multiple in Xunit to run all assertions in a block, revealing every failure instead of stopping at the first failing test for .NET core unit testing.
Add validation to greet and combine names to require a first name and throw an argument exception with the message 'empty first name'.
Learn to verify an exception is thrown without inspecting the message in .NET Core unit tests using Assert.Throws and Assert.That for an empty first name.
Implement inheritance with a customer type base class and two derived classes, basic and platinum, and create get customer details to return the correct type by order total.
Learn how to unit test get customer details by asserting object types: basic customer for orders under 100 and platinum customer for orders over 100, using NUnit or xUnit.
create a grading calculator class, implement score and attendance logic, and build five unit tests (four specific cases and one multi-input case) to validate grades.
Demonstrates building and testing a grading calculator with a test fixture, initializing a global calculator, and validating grades for various score and attendance inputs using both individual and parameterized tests.
Merge five unit tests into one comprehensive unit test for the grading calculator, part two of the assignment, and add a test that covers all conditions.
Combine multiple conditions into a single unit test for the grading calculator, returning strings like A, B, or F and confirming all seven scenarios pass.
Write and run the first unit test for the fibo series in a .NET Core project, using an arrange, act, and assert pattern and assertions to verify output.
Create a bank account class with a zero balance, implement deposit and withdrawal, add a get balance method, and introduce a logging class for calls.
Define a public logbook interface and a class that implements it, wire it through dependency injection, and log the deposit action to the console.
Demonstrates creating a bank account unit test, setting up a test fixture, and recognizing that involving a log book makes it an integration test rather than a true unit test.
Learn to test the bank account in isolation by replacing the log book with a log faker null object, turning the test back into a true unit test.
Mocking replaces production dependencies with test-time fake objects to isolate the class under test, enabling controlled behavior of dependencies like a logger and a repository with mocking frameworks.
Learn how to replace a brittle fake with a mocking framework from NuGet, creating a log book mock for ILogBook and using setup to control returns in unit tests.
Examine a product price flow where platinum customers receive a 20% discount via get price, and validate the result with unit tests while warning against unnecessary interface mocks.
Implement log to db and log balance after withdrawal, returning booleans based on balance checks, and unit test this withdrawal and logging logic in .NET Core with NUnit and XUnit.
Test the withdraw method with Moq in a .NET core unit test, mocking ILogBook to return true for log to DB and log balance, validating withdrawals.
Explore how to configure default return values in mock setups, validate withdrawal scenarios with balances, and use range checks to simulate negative inputs in unit tests.
Explore advanced mocking with moq to test return values from a logger method, including direct mock testing, lowercasing strings, and verifying behavior without bank account integration.
Demonstrate unit testing with Moq by testing a log with ref obj method, returning true for a customer reference and validating with assertions.
Understand Moq default return values in unit tests by examining how unconfigured inputs yield null for strings and false for booleans, and why specific setups influence outputs.
Learn how to mock properties in .NET Core unit tests using NUnit and XUnit, including setup of property getters and setters, and setup all properties, with order matters.
Explore callbacks with mocks in unit testing for .NET Core, modifying return values and parameters, using log to DB, and asserting results with before and after return callbacks.
Learn to verify mock interactions in unit tests with MOQ, including confirming method calls, exact call counts, and property get/set in a .NET Core NUnit or XUnit context.
learn how to create a dotnet six xunit project, install xunit and supporting packages, and start converting NUnit tests while preserving arrange, act, and assert concepts.
compare xUnit with NUnit by examining syntax differences, such as using [Fact] instead of [Test], omitting [TestFixture], and leveraging xUnit assertions and built-in helpers to ease test conversion.
Convert calculator unit tests from NUnit to xUnit by updating attributes, using facts and theories, applying inline data, and resolving build errors with project references.
Explore advanced Xunit tests for a calculator, including inline data with doubles, precision-based assertions, rounding behavior, and collection validations, highlighting NUnit vs Xunit differences.
Convert the gradient calculator to x unit test by uncommenting the code and completing the conversion, gaining practical x unit practice. Pause the video, then continue in the next video.
Convert a gradient calculator from nunit to xunit by using constructor-based setup, facts and theories with inline data, and assert equal to verify grades.
Practice assignment using XUnit to test a fibo series, focusing on collections, exploring alternatives, and resolving errors with XUnit.
implement and validate the fibo series tests in xUnit, using not empty, equal, sequence equal, and contains checks, ensuring correct counts and order before moving on to objects.
convert the product unit test to xunit, remove comments, add using statements, and use equal assertions to verify the result equals 40.
Convert the customer NUnit tests to xUnit, adapting assertions such as contains, startswith, regex, null, in range, and type; fix case sensitivity and complete the bank account xUnit assignment.
Convert bank account unit tests from NUnit to XUnit in net core, using fact, theory, and inline data to verify get balance and equality assertions.
Assemble a four-project dotnet six solution for a study room booking app, configure app settings, run migrations, and validate room availability with data access, models, and a web project.
Describe a four-project .net core architecture (web project, three class libraries) with repository pattern and EF Core, including models, view models, seeding, and service-driven booking flow for unit testing.
Create a class library for unit tests targeting the bongo dot models project and install NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk for the test framework. Test the date in future validation attribute by asserting that now plus 100 seconds is valid and now minus 100 seconds is invalid.
Demonstrate dynamic date validation in the Bongo models date checker with test cases that return boolean results and enforce the 'date must be in the future' message.
Set up a data access unit test project for the study room repositories, using an in-memory sql server to test get all and book operations with NUnit and XUnit.
Write and run a unit test for a study room booking repository using an in-memory sql server, validating save and retrieval of bookings with arrange, act, and assert phases.
Learn to write data access unit tests for .NET Core using NUnit & XUnit. Validate get all bookings in a repository with two bookings and a custom comparer.
Explore how shared database state makes unit tests fail when run together, and fix it with an in-memory Entity Framework Core DbContext, test order, and database cleanup.
Set up a bongo core unit test project in the solution, install NUnit and dependencies, and scaffold tests for the study room booking service's get all and book operations.
Learn unit testing in .NET Core with NUnit and XUnit by verifying that the get all bookings method is invoked once via mocked repositories in a study room booking service.
Learn to write a unit test for a happy path study room booking by setting up a booking request, mocking available rooms, and verifying the get all method returns them.
Showcases a unit test for study room booking using a mock repository and callback, verifying the book method is invoked and the saved booking matches the request.
Master unit testing of a study room booking in .NET Core with NUnit and XUnit, validating result properties and testing success versus no room available return codes using parameterized tests.
Explore separating unit tests for a study room booking service in .NET Core (NUnit & XUnit), using parameterized tests to verify booking IDs and ensure book method is not invoked.
Test the room booking controller. By mocking booking service, cover invalid model state, success, and no room available outcomes; set up bongo dot web dot test with NUnit and MOQ.
Develop unit tests for the room booking controller in .NET Core using NUnit and XUnit, mocking the study room booking service and verifying the index action invokes get all booking.
Learn to write a .NET Core unit test (NUnit & XUnit) that validates an invalid model state returns to the book view by asserting the view name in booking controller.
Write unit tests for the room booking controller in .NET core, asserting no room available returns a view with error, and a successful booking redirects to action with route values.
"Production application can break with a simple change that was unexpected to alter any other functionality" Sounds familiar right?!
Good news is, with well written unit test's this would be a thing of the past.
Automated testing has been a buzz word 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 main 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, we will learn the concepts related to unit testing. Today unit testing is an absolutely required skill from any professional developer. Companies expect from developers to know how to write unit tests using best practices. This course will help you setup a solid foundation with a real world example and how unit testing could be done in a .NET Core Web application with EF Core.
What is unit testing?
UNIT TESTING is a type of software testing where individual units or components of a software are tested. The purpose is to validate that each unit of the software code performs as expected.
Why learn unit testing?
Why should I learn unit testing? Why spend extra time to write code to test? Is manual testing not sufficient?
These are pretty common questions and I will answer them all but most of the times manual testing is much more time consuming and it is not as through as unit test. Unit tests take time once to write and can be executed for free every time!
As application grows, the cost of manual testing grows exponentially. And manual testing will never give 100% confidence with all the edge cases.. Automated tests help you to catch the bugs while it is in development phase, because of which they would be easier to resolve.
Will it help me with job?
Many times, skills comes with that will that skill help me achieve professionally. Unit testing is a very valuable skill with the current development cycle. It is a must have skill in most organizations for senior developers.
By end of this course you will have a solid foundation with unit testing. Along with a solid foundation we will implement what we learned in real world N-Tier web application with .NET 6 and EF Core.