Skip to content

Commit 97ec852

Browse files
authored
Update writing-csharp-tests.md (#183)
Minor edits to make document more readable.
1 parent 8f0a2c7 commit 97ec852

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ title: Writing Tests in C# for Blazor Components
55

66
# Writing Tests in C# for Blazor Components
77

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 little 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

10-
Use **bUnit** 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.
10+
Use **bUnit** to render the component under test, pass in it's parameters, inject required services, 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

@@ -40,12 +40,12 @@ This is a simple example, that tests the following `<HelloWorld>` component:
4040

4141
The following happens in the test above:
4242

43-
1. New up the disposable <xref:Bunit.TestContext>, and assign it using the `using var` syntax, to avoid unnecessary indention.
44-
2. Render the `<HelloWorld>` component using <xref:Bunit.TestContext>, which we do through the <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.ComponentParameter[])> method. We will cover passing parameters to components elsewhere.
45-
3. Verify the rendered markup from the `<HelloWorld>` component using the `MarkupMatches` method, which performs a semantic comparison of the expected markup with the rendered markup.
43+
1. Create a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assign it to ctx using the `using var` syntax, to avoid unnecessary source code indention.
44+
2. Render the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.ComponentParameter[])> method. We cover passing parameters to components elsewhere.
45+
3. Verify the rendered markup from the `<HelloWorld>` component, using the `MarkupMatches` method. The `MarkupMatches` method performs a semantic comparison of the expected markup with the rendered markup.
4646

4747
> [!TIP]
48-
> Learn more about how the semantic HTML/markup comparison in bUnit work, and how to customize it on the <xref:semantic-html-comparison> page.
48+
> Learn more about how the semantic HTML/markup comparison in bUnit works, and how to customize it on the <xref:semantic-html-comparison> page.
4949
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".
@@ -58,7 +58,7 @@ We can remove some boilerplate code from each test by making the <xref:Bunit.Tes
5858

5959
[!code-csharp[HelloWorldImplicitContextTest.cs](../../../samples/tests/xunit/HelloWorldImplicitContextTest.cs)]
6060

61-
Since xUnit instantiates test classes for each execution of test methods inside them and disposes them after each test method has run, we simply inherit from <xref:Bunit.TestContext>, and methods like <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.ComponentParameter[])> can now be called directly from each test, as seen in the listing above.
61+
Since xUnit instantiates test classes for each execution of test methods inside them and disposes of them after each test method has run, we simply inherit from <xref:Bunit.TestContext>, and methods like <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.ComponentParameter[])> can now be called directly from each test, as seen in the listing above.
6262

6363
# [NUnit](#tab/nunit)
6464

@@ -76,18 +76,18 @@ Then methods like <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.Com
7676

7777
[!code-csharp[BunitTestContext.cs](../../../samples/tests/mstest/BunitTestContext.cs)]
7878

79-
Since MSTest instantiates the test class is once, we cannot simply inherit directly from <xref:Bunit.TestContext>, as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, which is listed above, and use that to hook into MSTest's `[TestInitialize]` and `[TestCleanup]` methods, which runs before and after each test.
79+
Since MSTest instantiates the test class once, we cannot simply inherit directly from <xref:Bunit.TestContext>, as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, which is listed above, and use that to hook into MSTest's `[TestInitialize]` and `[TestCleanup]` methods, which runs before and after each test.
8080

8181
Then methods like <xref:Bunit.TestContext.RenderComponent``1(Bunit.Rendering.ComponentParameter[])> can now be called directly from each test, as seen in the listing above.
8282

8383
***
8484

8585
## Further Reading
8686

87-
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.
87+
With the basics out of the way, we will next look at how to pass parameters and inject services into our component under test, and after that, cover in more detail ways we can verify the outcome of a rendering.
8888

8989
- <xref:passing-parameters-to-components>
9090
- <xref:inject-services>
9191
- <xref:verify-markup>
9292
- <xref:verify-component-state>
93-
- <xref:trigger-event-handlers>
93+
- <xref:trigger-event-handlers>

0 commit comments

Comments
 (0)