You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/getting-started/create-test-project.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@ title: Creating a new bUnit Test Project
5
5
6
6
# Creating a new bUnit Test Project
7
7
8
-
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 generalpurpose test framework, like xUnit, NUnit, or MSTest, in addition to bUnit, to run your tests, and write your assertions.
8
+
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.
9
9
10
-
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 generalpurpose testing framework, read the following section.
10
+
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.
11
11
12
12
## Create a Test Project Manually
13
13
@@ -22,7 +22,7 @@ These steps look like this from the `dotnet` CLI:
22
22
23
23
**1. Create a new test project**
24
24
25
-
Use the following command (click on the tab that for the test framework you would like to use):
25
+
Use the following command (_click on the tab that for the test framework you would like to use_):
Then you need to change a few project settings, in particular we need to change the project's SDK to `Microsoft.NET.Sdk.Razor`, remember to set `RazorLangVersion` to `3.0`, and set the `<TargetFramework>` to `netcoreapp3.1`, since bUnit builds on `.netstandard 2.1`.
80
80
81
-
To do so, change the first part of the test project's`.csproj` file to look like this.:
81
+
To do so, change the first part of the test projects`.csproj` file to look like this.:
82
82
83
83
```xml
84
84
<ProjectSdk="Microsoft.NET.Sdk.Razor">
@@ -102,7 +102,7 @@ dotnet sln <NAME OF PROJECT>.sln add <NAME OF TEST PROJECT>
102
102
dotnet add <NAME OF COMPONENT PROJECT>.csproj reference <NAME OF TEST PROJECT>.csproj
103
103
```
104
104
105
-
The end result should be a test project with a `.csproj` that looks like this (other packages than bUnit might have different version numbers):
105
+
The result should be a test project with a `.csproj` that looks like this (other packages than bUnit might have different version numbers):
106
106
107
107
108
108
# [xUnit](#tab/xunit)
@@ -185,7 +185,7 @@ The end result should be a test project with a `.csproj` that looks like this (o
185
185
186
186
## Create a Test Project with bUnit Template
187
187
188
-
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 generalpurpose testing framework, but that will change in the future.
188
+
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.
189
189
190
190
The steps are as follows:
191
191
@@ -225,6 +225,6 @@ dotnet add <NAME OF COMPONENT PROJECT>.csproj reference <NAME OF TEST PROJECT>.c
225
225
226
226
## Further Reading
227
227
228
-
Now you are ready to write some times. To learn how, continue reading the <xref:writing-csharp-tests> and <xref:writing-razor-tests> pages.
228
+
Now you are ready to write some tests. To learn how, continue reading the <xref:writing-csharp-tests> and <xref:writing-razor-tests> pages.
229
229
230
230
For addition tips and tricks that will make writing tests easier, see the <xref:misc-test-tips> page.
Copy file name to clipboardExpand all lines: docs/docs/getting-started/fixture-options.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,25 @@ title: Fixture options in Razor Tests
5
5
6
6
# `<Fixture>` options in Razor Tests
7
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.
8
+
bUnit's <xref:Bunit.Fixture> component provides different parameters you can set on it, that changes the behavior of the test. It also allows you to both set up a component under test, and additional fragments, that can be used in the test.
9
9
10
10
11
11
## Parameters
12
12
13
-
All the parameters the `<Fixture>` support are shown in the listen below:
13
+
All the parameters the `<Fixture>` support is shown in the listing below:
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:
19
+
Let us 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
20
21
21
1.**<xref:Bunit.RazorTesting.FixtureBase`1.Setup>** and **<xref:Bunit.RazorTesting.FixtureBase`1.SetupAsync>:**
22
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
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
24
2.**<xref:Bunit.RazorTesting.FixtureBase`1.Test>** or **<xref:Bunit.RazorTesting.FixtureBase`1.TestAsync>:**
25
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.
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.
Copy file name to clipboardExpand all lines: docs/docs/getting-started/writing-csharp-tests.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,15 @@ title: Writing Tests in C# for Blazor Components
5
5
6
6
# Writing Tests in C# for Blazor Components
7
7
8
-
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*.
8
+
Testing Blazor components is a different from testing regular C# classes: Blazor components are *rendered*, they have the *Blazor component lifecycle*, during which we can *provide input* to them and where they *produce output*.
9
9
10
10
**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.
11
11
12
12
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.
13
13
14
14
## Creating a Basic Test
15
15
16
-
Lets see a simple example, where we test the following `<HelloWorld>` component:
16
+
Let us see a simple example, where we test the following `<HelloWorld>` component:
Copy file name to clipboardExpand all lines: docs/docs/getting-started/writing-razor-tests.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ title: Writing Tests in Razor Syntax for Blazor Components
8
8
> [!WARNING]
9
9
> Razor tests are currently only compatible with using xUnit as the general purpose testing framework.
10
10
11
-
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.
11
+
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.
12
12
13
13
> [!INFO]
14
14
> Tests declared inside Blazor test components can be discovered and invoked individually, and will show up in e.g. Visual Studio's Test Explorer.
@@ -17,15 +17,15 @@ A test for a Blazor component can be written in a Blazor component, using a mix
17
17
18
18
## Create a Test Specific `_Imports.razor` File
19
19
20
-
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:
20
+
Razor tests are written in Blazor test components. To make our life's a little easier, let us 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:
With that created, we are ready to create our first Razor test.
25
25
26
26
## Creating a Blazor Test Component
27
27
28
-
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>.
28
+
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, as long as they are based on the special bUnit test components, currently either <xref:Bunit.Fixture> or <xref:Bunit.SnapshotTest>.
29
29
30
30
Besides that, Blazor test components has to inherit from <xref:Bunit.TestComponentBase>, e.g.:
31
31
@@ -35,7 +35,7 @@ The following two sections will show how to create tests using bUnit's <xref:Bun
35
35
36
36
### Creating a Test using the `<Fixture>` Component
37
37
38
-
Lets see a simple example, where we test the following `<HelloWorld>` component using the bUnit <xref:Bunit.Fixture> component:
38
+
Let's see a simple example, where we test the following `<HelloWorld>` component using the bUnit <xref:Bunit.Fixture> component:
@@ -51,7 +51,7 @@ Let's break down what is going on in this test:
51
51
- The <xref:Bunit.Fixture> component's `Test` parameter takes a method, which is called when the test runs, and is passed the <xref:Bunit.Fixture> component.
52
52
- In the test method, we:
53
53
- Use the <xref:Bunit.Fixture.GetComponentUnderTest``1> to get the `HelloWorld` declared in the <xref:Bunit.Fixture>.
54
-
- Verify the rendered markup from the `HelloWorld` component using the <xref:Bunit.MarkupMatchesAssertExtensions.MarkupMatches(Bunit.IRenderedFragment,System.String,System.String)> method, which performs a semantic comparison of the expected markup with the rendered markup.
54
+
- Verify the rendered markup from the `HelloWorld` component using the <xref:Bunit.MarkupMatchesAssertExtensions.MarkupMatches> method, which performs a semantic comparison of the expected markup with the rendered markup.
55
55
56
56
> [!TIP]
57
57
> Learn more about how the semantic HTML/markup comparison in bUnit work, and how to customize it on the <xref:semantic-html-comparison> page.
@@ -63,7 +63,7 @@ Let's break down what is going on in this test:
63
63
64
64
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.
65
65
66
-
Lets see a simple example, where we test the following `<HelloWorld>` component using the bUnit <xref:Bunit.SnapshotTest> component:
66
+
Let's see a simple example, where we test the following `<HelloWorld>` component using the bUnit <xref:Bunit.SnapshotTest> component:
@@ -84,7 +84,7 @@ When the test runs, the <xref:Bunit.SnapshotTest> component will automatically c
84
84
85
85
### Passing Parameters to Components Under Test
86
86
87
-
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.
87
+
Since we are declaring our component under test in Razor syntax, passing parameters to the component under test is 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.
88
88
89
89
In this example, we are passing both attribute parameters and child content to the component under test, in this case, a basic `<Alert>` component:
90
90
@@ -94,7 +94,7 @@ Injecting services into the components under test is covered on the <xref:inject
94
94
95
95
## Further Reading
96
96
97
-
Now that we've covered the basics of writing tests using Razor syntax, you can continue digging deeper, e.g. by looking at:
97
+
Now that we have covered the basics of writing tests using Razor syntax, you can continue digging deeper, e.g. by looking at:
0 commit comments