Testing .NET Core Code with xUnit.net: Getting Started

xUnit.net is a modern testing framework that is also used by the .NET development team. This course teaches you how to get started writing xUnit.net automated tests to verify the application is working as expected, and help prevent costly bugs.
Course info
Rating
(51)
Level
Intermediate
Updated
Aug 25, 2017
Duration
2h 11m
Table of contents
Description
Course info
Rating
(51)
Level
Intermediate
Updated
Aug 25, 2017
Duration
2h 11m
Description

It's usually more expensive, time-consuming, and stressful to fix software bugs after they have been released to production environments. A good set of automated tests helps to verify that the application is working as expected, and helps to prevent bugs from getting into production. In this course, Testing .NET Core Code with xUnit.net: Getting Started, you'll cover an overview of automated testing that you'll be able to utilize in practice. First, you'll learn how to create xUnit.net automated tests that verify different types of results. Next, you'll explore how to customize and control test execution and categorization. Finally, you'll discover how to reduce the amount of test code needed with data-driven tests. When you're finished with this course, you'll have a foundational knowledge of xUnit.net that will help you to start writing your own automated tests.

About the author
About the author

With over 15 years experience, Jason Roberts is a Microsoft .NET MVP, freelance developer, and author.

More from the author
Working with Files and Streams in C#
Intermediate
3h 13m
12 Oct 2018
Error Handling in C# with Exceptions
Intermediate
1h 37m
6 Aug 2018
More courses by Jason Roberts
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone, my name's Jason Roberts, welcome to my course, Testing. NET Core Code with Xunit. NET: Getting Started. I'm a Microsoft MVP freelance developer and author. In this course, we're going to learn how to get started writing automated tests for our. NET Core applications using the Xunit. NET testing framework. Some of the main topics that we'll cover in this course include, how to set up a new test project and run tests, how to check different types of results are correct, how to customize and control test execution and how to reduce duplicated test code with data driven tests. By the end of this course, you'll understand how to use xUnit. net to test. NET Core Code to reduce the effects and costs, create happier teams and end users and improve long term delivery speeds. Before beginning the course, you should be familiar with writing basic C# code. I hope you'll join me on this journey with the testing. NET Core Code with Xunit. NET: Getting Started course at Pluralsight.

Determining Passing and Failing Tests with Asserts
Hi, welcome back. In the previous module, we got an overview of automated testing. We learned a bit about xUnit. net. We went and created an xUnit. net project. And we started to write our first test. We saw that our first test was incomplete however because we haven't yet added an assert. In this module, we'll go and complete this first test. And we'll also learn about the different types of asserts that xUnit provides. We'll start off this module by getting a brief overview of the concept of asserts. And we'll also discuss how many asserts we should have per test. We'll then head into the code and we'll write a number or additional tests. These tests will demonstrate how to assert against Boolean values. How to assert against string values including more advanced versions of string based asserts such as checking against regular expressions. We'll learn about numeric asserts and how to deal with floating point precision. We'll see how we can assert that the value is null. And the number of different ways we can assert on collections such as checking a collection contains a specific item. When we are writing asserts, we can also check that an object is of a specific type and also that two object instances are equal. Or learn how we can assert that an exception is thrown at the correct time. And also how we can assert that an expected event was raised. So let's kickoff this module by getting a brief overview of asserts.

Understanding and Controlling Test Execution
Hi, welcome back. Xunit. net has a lot of power when it comes to controlling the execution of the test that we're writing. In this module, we're going to start off by learning how we can categorize our tests so we can categorize individual test methods or we can categorize all tests within a test class. Once we've assigned tests to test categories, we'll see how we can execute them in Visual Studio Test Explorer and also using the dotnet command line interface. We'll learn that if we want to temporarily disable a test from executing, we can skip it. And we'll learn how we can output custom messages during the execution of our tests. We'll learn how we can use the features of Xunit. net to reduce the amounts of duplicated code we've got in our test methods. So for example, we'll learn how we can reuse the Arrange phase code and also create shared code to clean up after each test executes. If we need to perform setup for our tests and this this setup is expensive or time-consuming, it might slow down the tests, so we'll learn how we can share context between all of the tests in a test class to reduce any overheads. We'll also learn how we can perform a similar technique to share context between test methods in multiple test classes. So let's kick off this module by heading over to Visual Studio and learning how we can categorize our tests.

Creating Data-driven Tests
Hi, welcome back. In the previous module, we learned how to take control of the test execution life cycle. In this module, we're going to learn about data-driven tests and how they can help us reduce the amount of test code we need to write and maintain. So, in this module, we're going to start off by getting an overview of data-driven tests and how they help us reduce the amount of test code we need to write, and we'll also learn when we're using xUnit. net what the possible sources of test data are. We'll then head into Visual Studio, and we'll write some new tests for our player character. As we're doing this, we'll notice that we're creating some duplicated test code. We'll then start to go and refactor these multiple test methods to a single data-driven test. We'll then learn how we can share the same set of test data across multiple tests or multiple test classes, and then we'll learn how we can get test data from an external source. So we'll learn how we can specify test case data in an external. csv file and then use that to drive the data-driven test, and we'll also see how we can even go and create custom data-driven attributes. These custom attributes can contain hard-coded data, or we can combine them with the external data technique so that when the attribute is applied to a test method, the test data will come from an external source. So, let's kick off this module by getting a high-level overview of data-driven tests.