.NET Tools How-To's Livestreams

OSS Power-Ups: bUnit – Webinar Recording

The recording of our webinar, OSS Power-Ups: bUnit, with Egil Hansen and Steven Giesel, is available. This was the twelfth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webinars.


In this talk, you will learn how to get started creating tests for your Blazor components using bUnit, in a way that feels almost like regular unit testing.

bUnit is a library you add to a regular .NET testing project, e.g., a xUnit test project, that allows you to render your component with minimal effort, inspect the produced markup after each render and interact with the component under test. There is no browser involved, headless or otherwise, which means tests run fast and are predictable, just like regular unit tests.

The talk will cover all the basics, from setting up a bUnit test project to writing tests that render and interact with Blazor components.

Webinar agenda:

  • 00:00 – Welcome!
  • 01:11 – About OSS PowerUps
  • 03:21 – Hello, Egil and Steven!
  • 09:37 – What is bUnit, and why is it necessary?
  • 14:27 – Installing bUnit into a project
  • 20:00 – Testing a Counter component
  • 25:44 – Let’s make that test fail!
  • 26:44 – About Speed, JavaScript, and end-to-end tests
  • 32:24 – .NET CLI template (dotnet new)
  • 33:00 – Mixed test flavors (Razor vs. C#)
  • 36:02 – MarkupMatches assertions
  • 40:07 – Cascading parameters in Razor tests
  • 43:07 – What should you test?
  • 47:55 – Cascading parameters in C# tests
  • 52:02 – Razor compiler
  • 53:35 – Injecting dependencies/services into components
  • 55:38 – Stubbing components (e.g., third-party)
  • 67:58 – Generation of stub classes (source generators?)
  • 75:18 – Debugging
  • 78:12 – Mocking JavaScript calls
  • 84:30 – Outro

Resources:

About the presenter:

Egil Hansen

Experienced software developer/architect, international speaker, and Microsoft MVP for developer technologies, with a strong focus on creating maintainable software that solves real business problems in the cloud and on-prem, using techniques and practices such as domain-driven design, test-driven development, and following clean-code principles.

Egil is also the creator and maintainer of bUnit, an open-source library for testing Blazor components and AngleSharp.Diffing, a library for semantic comparison of HTML in C#.

Egil has worked with many technology stacks and architectural patterns throughout his career. He is now primarily focused on the .NET ecosystem, including backend and front-end technologies, and developing solutions running in the cloud.

Follow Egil on Twitter.

Steven Giesel

As an experienced .NET Engineer and a Microsoft MVP in Developer Technologies in the heart of Zurich, Steven Giesel brings a substantial breadth of knowledge and expertise to each project.

His enthusiasm for technology goes beyond his professional endeavors – he actively maintains various open-source libraries (for example, as co-maintainer for bUnit – a unit testing library for Blazor) and frequently speaks at user groups and conferences.

Furthermore, he has authored concise e-Books on .NET-related topics and peer-reviewed a book focused on building applications with Blazor WebAssembly.

Follow Steven on LinkedIn.

image description

Discover more