Skip to content

Commit 7e1115f

Browse files
committed
Docs update
1 parent 24785d3 commit 7e1115f

28 files changed

Lines changed: 157 additions & 130 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
uid: external-resources
3+
title: External Resources
4+
---
5+
16
# Presentations, guides, articles, tutorials, and blog posts
27
Here is a list of some of the content out on the web that covers bUnit. If you produce something you think can be useful to bUnit's users, feel free to add the content to this page and send a pull request.
38

docs/docs/getting-started.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/docs/getting-started/create-test-project.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
uid: create-test-project
3-
title: Creating a new bUnit test project
3+
title: Creating a new bUnit Test Project
44
---
55

6-
# Creating a new bUnit test project
6+
# Creating a new bUnit Test Project
77

88
Before you can write any tests, you need a place to put them - a test project. bUnit is not a unit test runner, so you need a general purpose test framework, like xUnit, NUnit, or MSTest, in addition to bUnit, to run your tests, and write your assertions.
99

1010
If you prefer xUnit, you can use the bUnit project template approached described in the [Create a test project with bUnit template](#create-a-test-project-with-bunit-template) section further down the page. If you want to use another general purpose testing framework, read the following section.
1111

12-
## Create a test project manually
12+
## Create a Test Project Manually
1313

1414
To create a project for testing you Blazor components that uses either of three general purpose test frameworks, you need to go through these steps:
1515

@@ -183,7 +183,7 @@ The end result should be a test project with a `.csproj` that looks like this (o
183183

184184
***
185185

186-
## Create a test project with bUnit template
186+
## Create a Test Project with bUnit Template
187187

188188
If you want to skip a few steps in the guide above, you can use the [bUnit test project template](https://www.nuget.org/packages/bunit.template/). The bUNit project template is only available for using with xUnit as the general purpose testing framework, but that will change in the future.
189189

@@ -223,7 +223,7 @@ dotnet sln <NAME OF PROJECT>.sln add <NAME OF TEST PROJECT>
223223
dotnet add <NAME OF COMPONENT PROJECT>.csproj reference <NAME OF TEST PROJECT>.csproj
224224
```
225225

226-
## Further reading
226+
## Further Reading
227227

228228
Now you are ready to write some times. To learn how, continue reading the <xref:writing-csharp-tests> and <xref:writing-razor-tests> pages.
229229

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
1-
---
1+
---
22
uid: fixture-options
3-
title: Fixture test options
3+
title: Fixture options in Razor Tests
44
---
55

6-
# `<Fixture>` options
6+
# `<Fixture>` options in Razor Tests
7+
8+
bUnit's <xref:Bunit.Fixture> component provides different parameters you can set on it, that changes the behavior of the test. It also allow you to both set up a component under test, and additional fragments, that can be used in the test.
9+
10+
11+
## Parameters
12+
13+
All the parameters the `<Fixture>` support are shown in the listen below:
14+
15+
[!code-html[](../../samples/tests/razor/AllFixtureParameters.razor)]
16+
17+
**Setup and Test methods:**
18+
19+
Let's start by looking at the parameters that takes a method as input first. The methods are called in the order they are listed in below, if provided, and should be used to the following:
20+
21+
1. **<xref:Bunit.RazorTesting.FixtureBase`1.Setup>** and **<xref:Bunit.RazorTesting.FixtureBase`1.SetupAsync>:**
22+
The `Setup` and `SetupAsync` method is called first, and you can provide both if needed. If both are provided, `Setup` is called first.
23+
They allows you to configures e.g. the <xref:Bunit.ITestContext.Services> collection of the <xref:Bunit.Fixture> component before the component under test or any fragments are rendered.
24+
2. **<xref:Bunit.RazorTesting.FixtureBase`1.Test>** or **<xref:Bunit.RazorTesting.FixtureBase`1.TestAsync>:**
25+
The `Test` or `TestAsync` methods are called after the setup methods.
26+
_One, and only one,_ of the test methods must be specified. Use the test method to access the component under test and any fragments defined in the fixture, and interact and assert against them.
27+
28+
**Other parameters**
29+
30+
The other parameters affect how the test runs, and how it is displayed in e.g. Visual Studio's Test Explorer:
31+
32+
1. **<xref:Bunit.RazorTesting.RazorTestBase.Description>:**
33+
If a description is provided, it will be displayed by the test runner when the test runs, and in Visual Studio's Test Explorer. If no description is provided, the name of the provided test method is used.
34+
2. **<xref:Bunit.RazorTesting.RazorTestBase.Skip>:**
35+
If the skip parameter is provided, the test is skipped and the text entered in the skip parameter is passed to the test runner as the reason to skip the test.
36+
3. **<xref:Bunit.RazorTesting.RazorTestBase.Timeout>:**
37+
If provided, the test runner will terminate the test after the specified amount of time.
38+
39+
## `<ComponentUnderTest>` and `<Fragment>`
40+
41+
## Getting `<ComponentUnderTest>` and `<Fragment>`
742

8-
TODO!
43+
## Example

docs/docs/getting-started/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
uid: getting-started
3-
title: Getting started with bUnit
3+
title: Getting Started with bUnit
44
---
55

6-
# Getting started with bUnit
6+
# Getting Started with bUnit
77

88
To get started writing tests for your Blazor components, you first need to set up a test project. Then you can start writing your tests, using either C# or Razor syntax.
99

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
---
1+
---
22
uid: snapshot-options
3-
title: SnapshotTest options
3+
title: SnapshotTest Options in Razor Tests
44
---
55

6-
# `<SnapshotTest>` options
6+
# `<SnapshotTest>` Options in Razor Tests
77

88
TODO!

docs/docs/getting-started/writing-csharp-tests.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
uid: writing-csharp-tests
3-
title: Writing tests in C# for Blazor components
3+
title: Writing Tests in C# for Blazor Components
44
---
55

6-
# Writing tests in C# for Blazor components
6+
# Writing Tests in C# for Blazor Components
77

88
Testing Blazor components is a different from testing regular C# classes: Blazor components are *rendered*, they have the *Blazor component life-cycle*, during which we can *provide input* to them and where they *produce output*.
99

1010
**bUnit** enables you to render the component you want to test, pass in parameters to it, inject services into it, and access the rendered component instance and the markup it has produced.
1111

1212
Rendering a component happens through bUnit's <xref:Bunit.TestContext>, and the result of the rendering, a <xref:Bunit.IRenderedComponent`1>, provides access to the component instance, and the markup produced by the component.
1313

14-
## Creating a basic test
14+
## Creating a Basic Test
1515

1616
Lets see a simple example, where we test the following `<HelloWorld>` component:
1717

@@ -50,7 +50,7 @@ In this test, we do the following:
5050
> [!TIP]
5151
> In bUnit tests, we like to use the abbreviation `CUT`, short for "component under test", to indicate the component that is being tested. This is inspired by the common testing abbreviation `SUT`, short for "system under test".
5252
53-
## Remove boilerplate code from tests
53+
## Remove Boilerplate Code from Tests
5454

5555
We can remove some boilerplate code from each test by making the <xref:Bunit.TestContext> implicitly available to the test class, so we do not have to have `using var ctx = new Bunit.TestContext();` in every test. This can be done like this:
5656

@@ -82,7 +82,7 @@ Then methods like <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.Com
8282

8383
***
8484

85-
## Further reading
85+
## Further Reading
8686

8787
With the basics out of the way, we will next look at how to pass parameters and inject services into our components under test, and after that, cover in more details the various ways we can verify the outcome of a rendering.
8888

docs/docs/getting-started/writing-razor-tests.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
22
uid: writing-razor-tests
3-
title: Writing tests in Razor syntax for Blazor components
3+
title: Writing Tests in Razor Syntax for Blazor Components
44
---
55

6-
# Writing tests in Razor syntax for Blazor components
6+
# Writing Tests in Razor Syntax for Blazor Components
77

88
> [!WARNING]
99
> Razor tests are currently only compatible with using xUnit as the general purpose testing framework.
1010
1111
A test for a Blazor component can be written in a Blazor component, using a mix of Razor and C# syntax. The advantage of this is the familiarity in declaring the component under test, and other HTML or Razor fragments that will be used in the test, in Razor and HTML markup. This is especially useful when testing components that takes a lot of parameters and child content as input.
1212

13-
> [!TIP]
13+
> [!INFO]
1414
> Tests declared inside Blazor test components can be discovered and invoked individually, and will show up in e.g. Visual Studio's Test Explorer.
1515
>
1616
> However, they will _not_ show up before the Blazor test component has been compiled into C# by the Blazor compiler, and if there are compile-errors from the Blazor compiler, they might appear to come and go in the Test Explorer.
1717
18-
## Create a test specific `_Imports.razor` file
18+
## Create a Test Specific `_Imports.razor` File
1919

2020
Razor tests are written in Blazor test components. To make our life's a little easier, let's first set up a `_Imports.razor` file, with the using statements we are going to be using throughout our tests. Simply add the following `_Imports.razor` to the root folder where you will be placing your Blazor test components:
2121

2222
[!code-html[_Imports.razor](../../samples/tests/razor/_Imports.razor#L3-)]
2323

2424
With that created, we are ready to create our first Razor test.
2525

26-
## Creating a Blazor test component
26+
## Creating a Blazor Test Component
2727

2828
A Blazor test component is conceptually very similar to a regular test class in e.g. xUnit or NUnit. You can define multiple tests inside a single test component, but those has to based on the special bUnit test components, currently either <xref:Bunit.Fixture> or <xref:Bunit.SnapshotTest>.
2929

@@ -33,7 +33,7 @@ Besides that, Blazor test components has to inherit from <xref:Bunit.TestCompon
3333

3434
The following two sections will show how to create tests using bUnit's <xref:Bunit.Fixture> and <xref:Bunit.SnapshotTest> components.
3535

36-
### Creating a test using the `<Fixture>` component
36+
### Creating a Test using the `<Fixture>` Component
3737

3838
Lets see a simple example, where we test the following `<HelloWorld>` component using the bUnit <xref:Bunit.Fixture> component:
3939

@@ -59,7 +59,7 @@ Let's break down what is going on in this test:
5959
> [!TIP]
6060
> In bUnit tests, we like to use the abbreviation `CUT`, short for "component under test", to indicate the component that is being tested. This is inspired by the common testing abbreviation `SUT`, short for "system under test".
6161
62-
### Creating a test using the `<SnapshotTest>` component
62+
### Creating a Test using the `<SnapshotTest>` Component
6363

6464
In snapshot testing, you declare your input (e.g. one or more component under test) and the expected output, and the library will automatically tell you if they do not match. With bUnit, this comparison is done using a smart built-in semantic HTML comparison logic.
6565

@@ -82,7 +82,7 @@ When the test runs, the <xref:Bunit.SnapshotTest> component will automatically c
8282
> [!TIP]
8383
> Learn more about how the semantic HTML/markup comparison in bUnit work, and how to customize it on the <xref:semantic-html-comparison> page.
8484
85-
### Passing parameters to components under test
85+
### Passing Parameters to Components Under Test
8686

8787
Since we are declaring our component under test in Razor syntax, passing parameters to the component under test is exactly the same as passing parameters in normal Blazor components. This is the same for tests created with both the <xref:Bunit.Fixture> and <xref:Bunit.SnapshotTest> components.
8888

@@ -92,7 +92,7 @@ In this example, we are passing both attribute parameters and child content to t
9292

9393
Injecting services into the components under test is covered on the <xref:inject-services-into-components> page.
9494

95-
## Further reading
95+
## Further Reading
9696

9797
Now that we've covered the basics of writing tests using Razor syntax, you can continue digging deeper, e.g. by looking at:
9898

docs/docs/misc-test-tips.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
uid: misc-test-tips
3-
title: Miscellaneous bUnit testing tips
3+
title: Miscellaneous bUnit Testing Tips
44
---
55

6-
# Miscellaneous bUnit testing tips
6+
# Miscellaneous bUnit Testing Tips
77

88
Here is a few testing tips and tricks that have proven useful to us.
99

10-
## Projects structure and tips and tricks
10+
## Projects Structure and Tips and Tricks
1111

1212
The recommended solution/project structure for a test and production code project set-up is:
1313

@@ -27,7 +27,7 @@ test
2727
| SubComponent1Test.cs
2828
```
2929

30-
## Use same root namespace and folder structure in both test- and production project
30+
## Use same Root Namespace and Folder Structure
3131

3232
A neat trick, which will limit the `import` statements needed in your test project, is to set the root namespace to the same as that of the production code project, _AND_ use the same folder structure as shown above. Following the example above, the `MyComponentLibTests.csproj` file should contain:
3333

@@ -37,7 +37,7 @@ A neat trick, which will limit the `import` statements needed in your test proje
3737
</PropertyGroup>
3838
```
3939

40-
## Capture logs from ILogger in test output
40+
## Capture Logs from ILogger in Test Output
4141

4242
TODO: Document XunitLogger and XunitLoggerFactory
4343

docs/docs/mocking/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
---
1+
---
22
uid: mocking
3-
title: Mocking component dependencies
3+
title: Mocking Component Dependencies
44
---
55

6-
# Mocking component dependencies
6+
# Mocking Component Dependencies
77

88
intro
99

0 commit comments

Comments
 (0)