
Learn how to write effective unit tests with MSTest, understand the importance of unit testing for beginners and developers, and prepare for interviews with practical techniques to test software automatically.
Define a unit test as a function that tests a unit of work, such as dividing numerator by denominator to yield a quotient with an assert comparing expected and actual.
Discover how to create your first unit test with MsTest in Visual Studio, including adding a unit test project, decorating test classes and methods, and applying arrange-act-assert.
Discover how unit tests identify bugs early and reduce production issues. See how they simplify understanding of complex code, provide documentation, and enable safe refactoring with greater developer confidence.
Unit tests drive the continuous integration pipeline by building the solution and running tests, rejecting changes that fail. Developers modify tests, run them locally, and await code reviews before check-ins.
Apply Roy Ashraf's unit test naming strategy using unit of work, state under test, and expected behavior. Align test classes and projects with code, then build and run tests.
Run unit tests in Visual Studio, including single, selected, and all tests. Use Test Explorer and enable auto run after build.
Discover how Visual Studio automatically generates unit tests across versions, from built-in support in 2010 to extensions in 2013 and reintroduced features in 2015, covering setup, naming, and execution.
Learn to debug C# unit tests in Visual Studio by setting breakpoints, launching the debugger, and stepping through code with F10, F11, and F5.
Explore grouping unit tests in Visual Studio's Test Explorer by outcome, duration, class, project, and traits, then run tests to identify fast, slow, failed, and not run tests.
Group unit tests by traits in the test explorer using test category and test property attributes, assigning calculator and demo categories and viewing them after a build.
Filter unit tests in Visual Studio via Test Explorer using class, project, trait, file path, error message, and fully qualified name filters, and view output with debug or test context.
Group unit tests in the Visual Studio Test Explorer using playlists and built-in traits like category, property, priority, owner; manage dot playlist XML files to run or remove tests.
Analyze code coverage to see how tests cover the divide method in the calculator library. Recognize that 100% coverage may not guarantee meaningful tests; exclude from code coverage attribute.
Learn how TestClass and TestMethod attributes enable Visual Studio to discover MSTest unit tests, and how duplicates or missing attributes cause compilation or discovery errors.
Learn to test divide by zero in a unit test by using the expected exception attribute, verifying the exception type and message, and rethrowing to pass the test.
Learn to unit test private methods in a calculator class, covering static and instance private methods, and testing for only positive numbers with argument exception handling.
Discover how an ordered test acts as a container for unit tests to guarantee a specific execution order, and learn how to add, arrange, run, and handle failures.
Demonstrates how a generic test wraps an executable in Visual Studio, uses a factorial console app to signal pass or fail via return codes, and handles format and overflow exceptions.
Learn how to run and filter MSTest unit tests from the command line using vs test.console.exe, including running multiple assemblies, selecting specific tests, applying test case filters, and logging results.
Identify test context as an abstract class that exposes the current test outcome, test name, and fully qualified class name; explain data connection, data row, and test cleanup behavior.
Learn to implement data driven unit tests using a SQL Server data source, validating an employee's email with a regex, and accessing test data via test context.
drive an MSTest unit test from an XML data source by adding employees.xml, configuring the data source for XML, and ensuring valid email data.
Drive a unit test with csv data by creating employees.csv, adding it to the test project, configuring the data source to csv, and fixing row data so tests pass.
Move data source configuration from code to an app.config file to enable environment switching without rebuilding. Switch among SQL Server, XML, and CSV sources in MSTest via the config.
Learn how test initialize and test cleanup attributes run before and after every unit test, with a rectangle example showing shared setup, cleanup, and the necessity of public setup methods.
Explore how classInitialize and classCleanup run once per test class, using public static void methods with a testContext parameter, to run before the first test and after all tests.
Explore how assembly initialize and assembly cleanup attributes manage setup and teardown across an assembly. Learn the required public static void signature with a test context and the single-attribute rule.
Explore how the MSTest timeout attribute enforces a test's maximum execution time with a 2000 millisecond example. Also learn how the ignore attribute skips specific tests or an entire class.
Use asserts to verify code correctness in unit tests by comparing expected and actual values, and explore the Assert, CollectionAssert, and StringAssert classes to handle assertion failures and exceptions.
Explore the MSTest assert class, using static methods to verify conditions, compare values, handle failures with messages, and cover is true, is null, and instance type checks.
Explore how to assert object equality by comparing customer properties, override equals and GetHashCode, and implement property-based assertions or a helper method for reliable unit tests.
Learn how collection assert validates collections in MSTest using equal, not equal, equivalent, contains, and is subset, with string, integer, and complex object examples.
Override the equals method in the customer class to compare name values, cast the object to a customer with as, return false if null, and override GetHashCode.
Learn to use CollectionAssert.AreEqual with a custom IComparer to compare two customer objects by name, implementing a three-parameter overload and handling nulls in MSTest unit tests.
Use the first overload of CollectionAssert.AreEqual to compare two lists of strings by projecting customer names with a select and lambda x.name, and confirm the unit test passes.
Explore how CollectionAssert.AreEquivalent differs from AreEqual by validating that two collections have the same elements regardless of order, with practical unit tests and customizable assertion messages.
Explore MSTest collection assertions: contains checks, is subset of, and all items unique, not null, or of a given type, illustrated with a customer hierarchy including savings customer.
Explore the StringAssert class in MSTest, including starts with, ends with, contains, and matches. Learn to customize assertion failure messages and validate email addresses with the regular expression class.
Practice TDD by writing a failing unit test, adding only enough code to pass, and refactoring for quality in a calculator project.
Test-driven development (TDD) produces clean, simplified code by focusing on requirements and small single-purpose classes, increasing code coverage and confidence as failing tests flag breaking changes early and prevent bugs.
What is the course about : This course is all about writing effective unit tests using C# programming language and MSTest framework. Along the way we will learn the concepts related to unit testing. Most organisations these days expect it's employees to have unit testing skills, as unit testing is becoming more and more important for the quality of the software applications.
How long is the course : The course is around 4 hours. All are video lectures. You will be able to download all the slides and code samples used in the course.
What will we be covering : We will start with, what is a unit test and we will write our first unit test, followed by benefits of unit tests. and unit test naming conventions.
We will also cover running, debugging, auto generating unit tests, grouping unit tests in visual studio, unit test traits, filtering, playlists, code coverage in visual studio, unit testing exceptions, unit testing private methods, visual studio ordered test, visual studio generic test, unit testing assertions and running unit tests from command line
The following visual studio unit testing attributes are discussed with examples