What is bUnit?
As mentioned in the introduction, some tests spin up web browsers to test pages/components, but bUnit takes another approach.
bUnit is made specifically for Blazor. It can define and set up tests using C# or Razor syntax. It can mock JavaScript interop as well as Blazor’s authentication and authorization. To make our components more testable, sometimes we need to think about these things from the beginning or make minor changes to our code.
bUnit doesn’t rely on a web browser but renders the output internally and exposes it to us so that we can test against predefined outputs. This is also a limitation – we are not testing the real site; we are testing the component, so think of this as unit tests, not integration tests.
It’s time for us to get our hands dirty, so let’s create a test project.