11 Testing your Blazor application
This chapter covers
- Creating a bUnit test project
- Writing tests that verify rendered markup
- Mocking authentication & authorization in tests
- Testing components that use JavaScript interop
Testing is a very important aspect of writing applications. When we have good tests in place we can produce higher quality applications, faster—Blazor applications are no exception. When it comes to testing Blazor apps, the three most common programmatic testing options are:
- Unit testing
- Integration testing
- End to end testing
Unit testing is the lowest level of testing we can utilize. When writing these types of tests, we focus on testing the smallest piece of functionality we can—such as a single method in a class. Due to this, these types of tests are extremely fast—individual tests run in milliseconds—which is handy, as we tend to write more unit tests than any other type. There are several frameworks available to help write unit tests, the three most common are xUnit (https://xunit.net), NUnit (https://nunit.org), and MSTest (https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest).