- Home
- .NET code examples
- Exploring xUnit: Theory, Assert methods and Fixtures
Exploring xUnit: Theory, Assert methods and Fixtures
Exploring xUnit has a numer of tutorials which looks at the different Theory attributes, what assert methods you can use in xUnit and how to use fixtures.
Download the code example
You'll need to fill out the code example form. We will send you an email where you can download the code example.
The code example will be in a zip file and will include all the Exploring xUnit tutorials separated by a numeric folder name.
Software
This is the software that will need to be installed onto your machine.
- Visual Studio 2022. Version 17.12.0 or above. It will work with the free community version.
- .NET 9 SDK. Version 9.0.0 or above.
Tutorials
Here are the different minimal API tutorials available:
How to use InlineData, MemberData and ClassData in xUnit
You can read more about how to use the InlineData, MemberData and ClassData attributes in xUnit, or watch the video:
In Visual Studio, open up 01/RoundTheCode.ExploringXUnit._01.sln from the code example zip file that you downloaded.
Go to Test and Test Explorer in the top menu. Run all the tests and they should all pass.
xUnit Assert basics: True/False, Equal, Same, Matches and more
You can read more about how to use some xUnit basic assert methods, or watch the video:
In Visual Studio, open up 02/RoundTheCode.ExploringXUnit._02.sln from the code example zip file that you downloaded.
Go to Test and Test Explorer in the top menu. Run all the tests and they should all pass, apart from the GetRating_HasGreatRating_ReturnsTrue test method in RatingHelperBooleanTests when the rating parameter is 11. This is because Assert.Fail will be called.
xUnit advanced Assert methods: Throws, IsType + more
You can read more about xUnit advanced assert methods, or watch the video:
In Visual Studio, open up 03/RoundTheCode.ExploringXUnit._03.sln from the code example zip file that you downloaded.
Go to Test and Test Explorer in the top menu. Run all the tests and they should all pass.
Use fixtures in xUnit for shared context in unit tests
You can read more about fixtures in xUnit, or watch the video:
In Visual Studio, open up 04/RoundTheCode.ExploringXUnit._04.sln from the code example zip file that you downloaded.
Go to Test and Test Explorer in the top menu. Run all the tests and they should all pass.
Related code examples
Using Moq in an xUnit project to unit test a .NET project
Download an xUnit and a .NET class library project that uses the Moq mocking framework to mock objects as part of unit tests.