
Automated testing is writing code to test code, replacing lengthy manual testing. It supports TDD, runs production and test code, and lets you verify functions quickly before deployment.
Catch bugs before deployment with automated tests, reducing defects and boosting software quality. Enable confident refactoring and ensure methods work across varied inputs.
Differentiate unit tests, integration tests, and end-to-end tests, and learn how external dependencies influence scope, speed, and reliability, with Selenium for end-to-end testing.
Discover the test pyramid: favor unit tests for fast, precise feedback, back them with integration tests for external dependencies, and use end-to-end tests sparingly for key functions.
Learn about popular C# testing frameworks like MSTest, NUnit, and xUnit, and focus on fundamentals of writing unit and integration tests. Start with MSTest in Visual Studio.
Download the provided zip file, open the Visual Studio solution, and begin writing your first unit test as you test code throughout the course.
Write your first unit test for the test ninja reservation class, verifying admin, the owner, or another user can cancel via the CanBeCancelled By method, using arrange-act-assert.
Develop unit tests for reservation cancellation scenarios using public void methods, following arrange, act, and assert, and decorate with TestMethod to enable test discovery in the test explorer.
Refactor with confidence using unit tests for C# developers. Tests document code and verify cancellation scenarios (admin, same user, another user) while returning the result of the expression.
Learn to run NUnit tests in visual studio, install NUnit and the NUnit test adapter, and switch from MS tests using TestFixture, Test, and readable assertions.
Master test-driven development basics by writing a failing test, adding the simplest code to pass, and refactoring. The course highlights code-first testing to ensure testable production code from the start.
Discover the course structure for unit testing in C#, covering fundamentals, test quality, naming and organizing tests, parameterized tests, and handling external dependencies via dependency injection and mocking.
Discover automated testing benefits, refactoring with confidence, and delivering higher quality software with fewer bugs while exploring unit, integration, and end-to-end tests and a basic unit test in Visual Studio.
Explore the fundamentals of unit testing, covering what to test and what not to test, plus naming, organizing, and writing clean, reliable tests that don't lie.
Treat unit tests as first-class citizens, keeping them clean, concise, and independent, with single responsibility and no logic, and ideally under ten lines, to reliably validate production code.
Get a recipe for unit tests: focus on clean code, test function outcomes for queries and commands, cover all paths, verify external calls, and avoid language or third party features.
Create a unit test project for each production project, separate unit and integration tests, and name test classes and methods to clearly reflect business rules, such as CanBeCancelledByTests.
Learn how Rider, a cross-platform IDE by Jet Brains, lets you run a single test or all tests in a class with a faster rest runner, using simple keyboard shortcuts.
Start your unit testing journey by writing a simple add method test with arrange, act, and assert, verifying a single execution path returns 3 for inputs 1 and 2.
In black-box testing for the max method, identify three execution paths: a greater, b greater, and equal, and write tests based on input scenarios rather than implementation.
Learn how to ensure test isolation by using NUnit's SetUp to initialize a fresh math object before each test. Understand TearDown's role for cleanup in integration tests.
Use NUnit's parameterized tests to replace multiple max method tests with one method taking A, B, and the expected result via test case attributes.
Learn to temporarily disable a test with NUnit's Ignore attribute, preserving a reason message, so you can focus on other work without deleting or commenting out tests.
Understand trustworthy tests by applying test-driven development and testing after production code. Simulate a bug, alter the production line, and ensure tests fail if they don’t validate the right behavior.
Avoid extremes on testing; maintain an essential automated test suite to catch bugs early, because the cost of late fixes outweighs upfront testing, with the double-entry bookkeeping analogy.
Explore the fundamentals of unit testing, building small, isolated tests with a single responsibility that verify outcomes, not implementation, and use setup and parameterized tests for reliability.
Explore unit testing scenarios by verifying methods that return values, test strings, and assess void methods, exceptions, and events, then discuss testing private and protected methods.
Learn how to write unit tests for strings in c#, using HtmlFormatter.FormatAsBold to wrap text in strong tags, and balance specific versus general assertions with optional ignore case.
Test the return type of methods by validating that GetCustomer returns NotFound when id is 0 and Ok otherwise, using two test paths in an ASP.NET MVC controller.
Demonstrate unit testing void methods in C#, validating state changes inside an ErrorLogger's Log method, including lastError updates, input validation, and test assertions.
Learn to test methods that throw exceptions in unit testing for c# developers by using a parameterized test for null, empty, and whitespace inputs, and assert ArgumentNullException with a delegate.
Learn to test methods that raise events by subscribing to the ErrorLogged event before acting. Capture the event argument (a new guid) and assert it is not Guid.Empty.
Test the public API, not private or protected methods, to avoid fragile tests tied to implementation details; refactor complex logic into separate public classes when needed.
Explore how code coverage reveals untested lines, compare DotCover with Visual Studio Enterprise Edition and ReSharper Ultimate, and learn to test all execution paths using black-box thinking.
Assess where automated testing adds value, refactor critical legacy parts to be testable, focus on key components for startups, and educate the team to write cleaner code before testing.
Apply unit testing best practices by validating methods that return strings or collections, void methods, exceptions, and events, while testing only the public interface, ahead of exercises.
Practice writing unit tests for the fizzbuzz function in c# using GetOutput as a black box. Validate outputs for numbers divisible by 3, by 5, or by both.
demonstrates using live templates in Visual Studio or Rider to generate unit test methods for FizzBuzz, including test fixture setup and GetOutput scenarios for divisible by 3, 5, or both.
Calculate demerit points by awarding one point for every five kilometers over the 65 km/h limit, so 15 over yields three points; write unit tests for the demeritpoints function.
Learn to implement and refactor unit tests for a DemeritPointsCalculator, using parameterized test cases, exception handling for out-of-range speeds, and a MaxSpeed constant.
Write unit tests for the stack class, validating push, pop, and peek operations and the count property, and review the solution to ensure correct stack behavior.
Write unit tests for a stack class in a C# project, validating push with null throws argument null exception, and push, pop, and peek via public API, with count checks.
Learn to unit test classes that depend on external resources by decoupling dependencies and using test doubles or fakes, as in a video service replacing a file class.
Refactor legacy code into a testable, loosely coupled design by extracting resource logic into a class and using an interface as a contract; inject dependencies from outside, enabling test doubles.
Learn to refactor legacy code into a loosely coupled, testable design by extracting file access into a FileReader, creating an IFileReader interface, and using a fake implementation for unit tests.
Explore dependency injection by method parameters, properties, and constructors; inject via method parameters with an IFileReader to achieve loose coupling and testability using real and fake file readers.
Learn how to inject dependencies via properties using a FileReader property to replace method parameter injection, ensuring production uses a real reader while tests can fake it.
Implement constructor injection by passing IFileReader to the video service, replacing property injection, and enable test doubles with an optional constructor.
Understand dependency injection frameworks that automate object creation at run time via a container of interfaces and implementations, with examples like Ninject and Autofac across ASP.NET, Xamarin, and WPF apps.
Explore mocking frameworks to dynamically create or mock objects for unit tests, enabling ReadVideoTitle path coverage. Replace FakeFileReader with mocks that return real json and simulate exceptions or events.
Create mock objects with the Moq library to test external dependencies, configure IFileReader behavior, and inject mock.Object into your video service.
Contrast state-based testing with interaction testing to verify external resource interactions, such as ensuring the order service calls storage with the correct order object, while favoring state-based testing.
Create a unit test for the order service to verify storage.Store is called with the same order passed to PlaceOrder, using a mock IStorage and Verify.
Use mocks sparingly to remove external resources from tests. Avoid sprawling interfaces and bloated constructors, and keep tests fast and reliable by focusing on external behavior rather than implementation.
Demonstrate how GetPrice applies a 30 percent discount for gold customers based on ListPrice and contrast simple unit tests with mocks for ICustomer.
Unit and integration tests are the developer’s responsibility; before committing code, cover new features or fixes with tests, while end-to-end tests may be written by developers or test engineers.
Practice writing unit tests for the VideoService.GetUnprocessedVideosAsCsv method using a mocked VideoContext to fetch unprocessed videos, collect their IDs, and return a comma-separated string.
Refactor by extracting database access into a video repository to isolate external resources, then inject an IVideoRepository interface into VideoService for testable, loosely coupled unit testing.
Learn to unit test the GetUnprocessedVideos method with mocks, cover empty and multiple videos, and consider repository dependencies and constructor design to keep tests focused.
Practice unit testing the InstallerHelper class by examining its DownloadInstaller method, which uses WebClient to download a file from a constructed URL and returns true or false.
Refactor the installer helper by extracting a file downloader interface to isolate external resource access, enabling dependency injection and two unit tests for download success and failure.
Create a unit test class for installer helper, use a test fixture and setup to mock IFileDownloader, and verify download outcomes (false on web exception, true when download completes).
Explore unit testing the delete operation in an ASP.NET MVC-like EmployeeController by simulating entity framework interactions, extracting storage into EmployeeStorage, and testing state-based results and storage calls.
Refactor the EmployeeController to delegate deletion to a new EmployeeStorage that encapsulates database access, extract an IEmployeeStorage interface, and inject it to achieve proper separation of concerns.
Learn how to unit test the EmployeeController by mocking IEmployeeStorage, verifying DeleteEmployee called with 1, and asserting RedirectToAction returns a RedirectResult, while noting integration tests for database deletion.
Develop unit tests for the OverlappingBookingsExist booking overlap check in BookingHelper, refactoring for loose coupling and testability while validating cancellations, querying non-cancelled bookings, and returning the first overlap reference.
Develop comprehensive unit tests for overlapping bookings in C# by defining all test cases—before, in middle, after overlaps, and cancellation scenarios—and organize tests in a BookingHelperTests class with mocking.
Extracts an IBookingRepository to encapsulate the active bookings query via GetActiveBookings, with an optional excluded booking id, enabling unit testing through dependency injection and interface-based design.
Write the first test for BookingHelper.OverlappingBookingsExist by mocking IBookingRepository, returning an IQueryable of existing bookings, then verify a non overlapping booking yields an empty result.
Refactors unit tests by extracting arrive on and depart on helpers, introducing a shared existing booking, and using before and after helpers with name arguments to remove magic numbers.
Duplicate the second test to save time, verify overlapping bookings return the existing booking reference, and adjust logic to start before and simulate the middle scenario.
Unit testing for C# developers guides fixing a bug in booking overlap logic by using a proven two-date overlap condition and expanding tests to validate all scenarios.
Develop seven unit tests for the booking helper, covering overlapping and non-overlapping date ranges and ensuring cancelled bookings are excluded.
Explore unit testing for C# by writing tests for SendStatementEmails, isolate external resources, and apply dependency injection to inject SaveStatement and EmailFile dependencies.
Refactor to improve testability by extracting interfaces (IUnitOfWork, IStatementGenerator, IEmailSender, IXtraMessageBox), replacing static calls with instance methods, and injecting dependencies via constructors.
Test the outcome of command functions and verify interactions with collaborators like statementGenerator and emailSender; consider refactoring to void, and begin with state-based tests before moving to interaction tests.
Learn to write the first interaction test for a C# application service by mocking the unit of work and collaborators, and verifying statement generation and email sending for housekeepers.
Keep tests clean by introducing a setUp method, promoting shared objects to private fields, and reducing duplication so each test starts with fresh unit of work and mocks.
Explore black-box unit testing to ensure no statements are generated when a housekeeper lacks a valid email, using mock verification to never call SaveStatement and refining code with String.IsNullOrWhiteSpace.
Master c# unit testing with mocks and setup to verify email sending of the statement when a valid file name is returned, and prevent sending for null or empty names.
Learn how to clean up C# unit tests by moving mock setup to SetUp, using lazy evaluation with lambdas, and extracting helper methods like VerifyEmailNotSent and VerifyEmailSent for clarity.
Write a unit test for email sending failure by configuring the mock to throw an exception, then verify the messageBox displays with an ok button.
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:
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:
You’ll get: