bUnit is a testing library for Blazor components. Its goal is to make it easy to write comprehensive, stable unit tests for components. We will learn the steps to create a bUnit test class from setup to rendering to validation. This test will focus on testing a static component with a simple rendering operation. First, we must have a … Continue reading How-To: Write bUnit Test for Component
Tag: Visual Studio
How-To: Create New Blazor Component
Blazor apps are based on components. A component in Blazor is the atomic unit of composition for any UI element, such as a page, control, dialog, or data entry form. Components are .NET C# classes built into assemblies. They can: Define UI rendering logic.Handle user events.Be nested and reused.Be shared and distributed as Razor class libraries or NuGet packages. The … Continue reading How-To: Create New Blazor Component
How-To: Unit Test Blazor Pages with DataBinding
Continuing with our use of the bUnit testing library for Blazor components. We will investigate how to create unit and component tests for pages/components that use both one-way and two-way data bindings. We will look at changing data on the page and performing actions (like button clicks) and then seeing how that impacts the page rendering. … Continue reading How-To: Unit Test Blazor Pages with DataBinding
How-To: Create New Page in Blazor
In Blazor, a page is the basic unit of navigation. It is the top-level component that can be reached via a URL So, when we want a new view in your Blazor app, we will need to create a new page. In all other aspects, a page and a component have equivalent functionality. First, we … Continue reading How-To: Create New Page in Blazor
How-to: Add bUnit Test Project to Blazor Solution
Having automated tests for our Blazor applications is very important. We can use xUnit (or any other) test framework to write unit tests for the C# classes in our app. However, some part of our logic (even if it's just the databinding logic) lives in Blazor components and pages. For those to be tested, we … Continue reading How-to: Add bUnit Test Project to Blazor Solution
How-To: Create Blazor WASM Project
Here are the quick steps to create a Blazor WebAssembly project for .NET 5 in Visual Studio. The basic template creates some extra pages and components, so we will also clean it up to produce a minimal project with a home page. This is a great starting point for all of our Blazor projects. Initial … Continue reading How-To: Create Blazor WASM Project
Lesson 1.8: bUnit to Test Blazor Components
Testing source code is one part of what we need for our game. Since we're building on Blazor, we're going to need a way to test Blazor components as well. And while a lot of Blazor is just plain C# classes that extend and render controls. There is an infrastructure in place to render those … Continue reading Lesson 1.8: bUnit to Test Blazor Components
Lesson 1.7: Adding Unit Test Project
Before we get too far along in coding the Simple RPG game, we need to enable building and running unit tests for our project. I've followed various forms of TDD (test-driven development) over the years. And I'm not a purest about writing tests prior to writing code. But I do firmly believe in creating tests … Continue reading Lesson 1.7: Adding Unit Test Project
Lesson 1.4: Create Initial Blazor Project
Now that we have a source repository (from lesson 1.3) for our work, we're going to create the initial Blazor application project. Let's start by launching Visual Studio 2019. The first thing we will see is a dialog where we can clone code, open projects, create projects, etc. We are going to start by cloning … Continue reading Lesson 1.4: Create Initial Blazor Project
Lesson 1.2: The Prerequisites
To follow along with these lessons, we are going to need some basic knowledge and tools. This in not an introductory tutorial on programming or the basics of C#. If you would like some of those there are a lot of materials and tutorials for that. But you can certainly pick things up along the … Continue reading Lesson 1.2: The Prerequisites