Skip to content

Commit cf906cd

Browse files
committed
updates to docs
1 parent 0640042 commit cf906cd

12 files changed

+110
-84
lines changed

CHANGELOG.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Changelog
2+
23
All notable changes to **bUnit** will be documented in this file. The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
34

4-
## [1.0.0-beta-7] - 2020-05-15
5+
## [1.0.0-beta-7] - 2020-05-19
56

6-
There are three big changes in bUnit in this release, as well as a whole host of small new features, improvements to the API, and bug fixes. The three big changes are:
7+
There are three big changes in bUnit in this release, as well as a whole host of small new features, improvements to the API, and bug fixes. The three big changes are:
78

89
1. A splitting of the library
9-
2. Discovery of razor base tests, and
10+
2. Discovery of razor base tests, and
1011
3. A strongly typed way to pass parameters to a component under test.
1112

1213
There are also some breaking changes, which we will cover first.
@@ -32,7 +33,7 @@ For example, if you have a razor based test that looks like this currently:
3233
void TestSetup() => Services.AddMockJsRuntime();
3334

3435
void Test001()
35-
{
36+
{
3637
var cut = GetComponentUnderTest<Counter>();
3738
var fragment = GetFragment();
3839
}
@@ -65,6 +66,7 @@ It is a little more typing, but it is also a lot more obvious what is going on,
6566
In addition to this, the `Tests` and `TestsAsync` methods on `<Fixture>` have been deprecated in this release and throws a runtime exception if used. They were not very used and caused confusion about the state of the components under test between the method calls. Now you can only specify either a `Test` or `TestAsync` method per `<Fixture>`.
6667

6768
#### WaitForRender removed
69+
6870
The `WaitForRender` method has been removed entirely from the library. Since it would only wait for one render, it had a very specific use case, where as the more general `WaitForAssertion` or `WaitForState` will wait for any number of renders, until the assertion passes, or the state predicate returns true. These make them much better suited to create stable tests.
6971

7072
With `WaitForRender`, you would pass in an action that would cause a render before attempting your assertion, e.g.:
@@ -75,15 +77,15 @@ cut.WaitForRender(() => mockForecastService.Task.SetResult(forecasts));
7577
Assert.Equal("...", cut.Markup);
7678
```
7779

78-
This can now be changed to first call the action that will trigger the render, and then wait for an assertio to pass, using `WaitForAssertion`:
80+
This can now be changed to first call the action that will trigger the render, and then wait for an assertion to pass, using `WaitForAssertion`:
7981

8082
```c#
8183
mockForecastService.Task.SetResult(forecasts);
8284

8385
cut.WaitForAssertion(() => Assert.Equal("...", cut.Markup));
8486
```
8587

86-
The two "wait for" methods are also only available through a rendered fragment or rendered component now.
88+
The two "wait for" methods are also only available through a rendered fragment or rendered component now.
8789

8890
#### ComponentTestFixture deprecated
8991

@@ -93,7 +95,8 @@ The component parameter factory methods are now also available in the more gener
9395

9496
That covers the most important breaking changes. Now lets look at the other big changes.
9597

96-
### Splitting the library
98+
### Splitting up the library
99+
97100
In this release sees bUnit refactored and split up into three different sub libraries. The reasons for doing this are:
98101

99102
- To make it possible to extract the direct dependency on xUnit and easily add support for NUnit or MSTest
@@ -109,13 +112,15 @@ The three parts of the library is now:
109112
To keep things compatible with previous releases, an additional package is available, **bUnit**, which includes all of three libraries. That means existing users should be able to keep their single `<PackageReference Include="bunit">` in their projects.
110113

111114
### Discovery of Razor based tests
115+
112116
One of the pain points of writing Razor based tests in `.razor` files was that the individual tests was not correctly discovered. That meant that if had multiple tests in a file, you would not see them in Visual Studios Test Explorer individually, you could not run them individually, and error was not reported individually.
113117

114118
This has changed with the _bUnit.xUnit_ library, that now includes a way for it to discover individual razor tests, currently either a `<Fixture>` or `<SnapshotTest>` inside test components defined in `.razor` files. It also enables you to navigate to the test by double clicking on it in the Test Explorer, and you can run each test individually, and see error reports individually.
115119

116120
**WARNING:** You still have to wait for the Blazor compiler to translate the `.razor` files into `.cs` files, before the tests show up in the Test Explorer, and the this can trip up the Test Explorer. So while this feature is a big improvement to razor based testing, it is still not perfect, and more works need to be done to refine it.
117121

118122
### Strongly typed component parameters
123+
119124
If you prefer writing your tests in C# only, you will be happy to know that there is now a new strongly typed way to pass parameters to components, using a builder. E.g., to render a `ContactInfo` component:
120125

121126
```c#
@@ -129,6 +134,8 @@ There are a bunch of different `Add` methods available on the builder, that allo
129134

130135
The old way using the component parameter factory methods are still available if you prefer that syntax.
131136

137+
NOTE: The parameter builder API is experimental at this point, and will likely change.
138+
132139
### NuGet downloads
133140
The latest version of the library is available on NuGet in various incarnations:
134141

@@ -141,8 +148,9 @@ The latest version of the library is available on NuGet in various incarnations:
141148
| bUnit.template | Template, which currently creates an xUnit based bUnit test projects only | [![Nuget](https://img.shields.io/nuget/dt/bunit.template?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.template/) |
142149

143150
### Contributions
144-
Thanks to [Martin Stühmer (@samtrion)](https://github.com/samtrion) and [Stef Heyenrath (@StefH)](https://github.com/StefH) for their code contributions in this release.
145-
Also a big thank to all you who have contributed by raising issues, participated in issues by helping answer questions and providing input on design and technical issues.
151+
Thanks to [Martin Stühmer (@samtrion)](https://github.com/samtrion) and [Stef Heyenrath (@StefH)](https://github.com/StefH) for their code contributions in this release, and to [Brad Wilson (@bradwilson)](https://github.com/bradwilson) for his help with enabling xUnit to discover and run Razor based tests.
152+
153+
Also a big thank to all you who have contributed by raising issues, participated in issues by helping answer questions and providing input on design and technical issues.
146154

147155
### Added
148156
- A new event, `OnAfterRender`, has been added to `IRenderedFragmentBase`, which `IRenderedFragment` inherits from. Subscribers will be invoked each time the rendered fragment is re-rendered. Related issue [#118](https://github.com/egil/bunit/issues/118).
@@ -153,6 +161,8 @@ Also a big thank to all you who have contributed by raising issues, participated
153161
- The two razor test types, `<Fixture>` and `<SnapshotTest>`, can now be **skipped**. by setting the `Skip="some reason for skipping"` parameter. Note, this requires support from the test runner, which current only includes bUnit.xUnit. Related issue: [#77](https://github.com/egil/bunit/issues/77).
154162
- The two razor test types, `<Fixture>` and `<SnapshotTest>`, can now have a **timeout** specified, by setting the `Timeout="TimeSpan.FromSeconds(2)"` parameter. Note, this requires support from the test runner, which current only includes bUnit.xUnit.
155163
- An `InvokeAsync` method has been added to the `IRenderedFragmentBase` type, which allows invoking of an action in the context of the associated renderer. Related issue: [#82](https://github.com/egil/bunit/issues/82).
164+
- Enabled the "navigate to test" in Test Explorer. Related issue: [#106](https://github.com/egil/bunit/issues/106).
165+
- Enabled xUnit to discover and run Razor-based tests. Thanks to [Brad Wilson (@bradwilson)](https://github.com/bradwilson) for his help with this. Related issue: [#4](https://github.com/egil/bunit/issues/4).
156166

157167
### Changed
158168
- Better error description from `MarkupMatches` when two sets of markup are different.

docs/docs/basics-of-blazor-component-testing.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ There are three different ways of doing this in the library:
66

77
1. **C# based tests**
88
With C# based tests, you write all your testing logic in C# files, i.e. like regular unit tests.
9-
2. **Razor based tests _(EXPERIMENTAL FEATURE)_**
9+
2. **Razor based tests**
1010
With Razor based tests, you write tests in `.razor` files, which allows you to declare, in Razor syntax, the component under test and other markup fragments you need. You still write your assertions via C# in the .razor file, inside `@code {...}` blocks.
11-
3. **Snapshot tests _(EXPERIMENTAL FEATURE)_**
11+
3. **Snapshot tests**
1212
Snapshot tests are written in `.razor` files. A test contains a definition of an input markup/component and the expected output markup. The library will then automatically perform an semantic HTML comparison. Very little C# is needed in this, usually only to configure services.
1313

1414
In _Snapshot testing_, the rendering and verification is automatic.
1515

1616
For _C# based tests_ and _Razor based tests_, we have the following concepts to help us render our components and markup fragments:
1717

1818
- `ITestContext` for rendering using the RenderComponent method. The test context also allows you to configure services that should be available during rendering of components.
19-
- `IRazorTestContext` extends `ITestContext` with methods for getting the declared components under test and any (markup) fragments in Razor based tests.
2019

2120
And the following concepts to help us access the rendered markup and component:
2221

@@ -26,8 +25,4 @@ And the following concepts to help us access the rendered markup and component:
2625

2726
- `IRenderedComponent<TComponent>` extends `IRenderedFragment` with methods for rendering a component again with new parameters if needed, and a property for accessing the instance of the component.
2827

29-
The diagram below shows the four interfaces, their relationships to each other, and available methods.
30-
31-
![Test context and rendered fragment/component diagram](/images/test-context-rendered-fragment-diagram.png)
32-
33-
This is the basics of how components and markup is rendered and afterword's accessed for verification and further inspection.
28+
This is the basics of how components and markup is rendered and accessed for verification and further inspection.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Creating a new bUnit with MSTest test project
2+
3+
TODO
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Creating a new bUnit with NUnit test project
2+
3+
TODO

docs/docs/creating-a-new-test-project.md renamed to docs/docs/creating-a-new-bunit-xunit-project.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
# Creating a new test project
1+
# Creating a new bUnit with xUnit test project
22

33
To create a project for testing you Blazor components, first install the [bUnit Project Template](https://www.nuget.org/packages/bunit.template/) from NuGet, using this command:
44

5-
```
6-
dotnet new --install bunit.template::1.0.0-beta-6
5+
```bash
6+
dotnet new --install Razor.Components.Testing.Library.Template::#{VERSION}#
77
```
88

99
Then to create a new project, use the following command:
1010

11-
```
12-
dotnet new bunit -o <NAME OF PROJECT>
11+
```bash
12+
dotnet new razortest -o <NAME OF TEST PROJECT>
1313
```
1414

1515
where `-o <NAME OF PROJECT>` is used to name the test project.
1616

17+
**Optional CLI steps**
18+
19+
Link the test project to your solution
20+
21+
```bash
22+
dotnet sln <NAME OF PROJECT>.sln add <NAME OF TEST PROJECT>
23+
```
24+
25+
Add a reference your components to be tested in your test project.
26+
27+
```bash
28+
dotnet add <NAME OF COMPONENT PROJECT>.csproj reference <NAME OF TEST PROJECT>.csproj
29+
```
30+
1731
## Creating a new Blazor test project manually
1832

1933
If you do not want to use the Blazor test project template, you can create an empty class library and the modify the `.csproj` to match the following:
@@ -27,9 +41,7 @@ If you do not want to use the Blazor test project template, you can create an em
2741
</PropertyGroup>
2842

2943
<ItemGroup>
30-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.0" />
31-
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.0" />
32-
<PackageReference Include="bunit" Version="1.0.0-beta-6" />
44+
<PackageReference Include="bunit" Version="#{VERSION}#" />
3345
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
3446
<PackageReference Include="xunit" Version="2.4.1" />
3547
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">

0 commit comments

Comments
 (0)