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: CHANGELOG.md
+19-9Lines changed: 19 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,13 @@
1
1
# Changelog
2
+
2
3
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).
3
4
4
-
## [1.0.0-beta-7] - 2020-05-15
5
+
## [1.0.0-beta-7] - 2020-05-19
5
6
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:
7
8
8
9
1. A splitting of the library
9
-
2. Discovery of razor base tests, and
10
+
2. Discovery of razor base tests, and
10
11
3. A strongly typed way to pass parameters to a component under test.
11
12
12
13
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:
32
33
voidTestSetup() =>Services.AddMockJsRuntime();
33
34
34
35
voidTest001()
35
-
{
36
+
{
36
37
varcut=GetComponentUnderTest<Counter>();
37
38
varfragment=GetFragment();
38
39
}
@@ -65,6 +66,7 @@ It is a little more typing, but it is also a lot more obvious what is going on,
65
66
Inadditiontothis, the `Tests` and `TestsAsync` methodson `<Fixture>` havebeendeprecatedinthisreleaseandthrowsaruntimeexceptionifused. Theywerenotveryusedandcausedconfusionaboutthestateofthecomponentsundertestbetweenthemethodcalls. Nowyoucanonlyspecifyeithera `Test` or `TestAsync` methodper `<Fixture>`.
66
67
67
68
#### WaitForRender removed
69
+
68
70
The `WaitForRender` methodhasbeenremovedentirelyfromthelibrary. Sinceitwouldonlywaitfor 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.
69
71
70
72
With `WaitForRender`, you would pass in an action that would cause a render before attempting your assertion, e.g.:
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.
87
89
88
90
#### ComponentTestFixture deprecated
89
91
@@ -93,7 +95,8 @@ The component parameter factory methods are now also available in the more gener
93
95
94
96
That covers the most important breaking changes. Now lets look at the other big changes.
95
97
96
-
### Splitting the library
98
+
### Splitting up the library
99
+
97
100
In this release sees bUnit refactored and split up into three different sub libraries. The reasons for doing this are:
98
101
99
102
- 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:
109
112
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.
110
113
111
114
### Discovery of Razor based tests
115
+
112
116
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.
113
117
114
118
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.
115
119
116
120
**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.
117
121
118
122
### Strongly typed component parameters
123
+
119
124
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:
120
125
121
126
```c#
@@ -129,6 +134,8 @@ There are a bunch of different `Add` methods available on the builder, that allo
129
134
130
135
The old way using the component parameter factory methods are still available if you prefer that syntax.
131
136
137
+
NOTE: The parameter builder API is experimental at this point, and will likely change.
138
+
132
139
### NuGet downloads
133
140
The latest version of the library is available on NuGet in various incarnations:
134
141
@@ -141,8 +148,9 @@ The latest version of the library is available on NuGet in various incarnations:
141
148
| bUnit.template | Template, which currently creates an xUnit based bUnit test projects only |[](https://www.nuget.org/packages/bunit.template/)|
142
149
143
150
### 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.
146
154
147
155
### Added
148
156
- 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
153
161
- 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).
154
162
- 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.
155
163
- 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).
156
166
157
167
### Changed
158
168
- Better error description from `MarkupMatches` when two sets of markup are different.
Copy file name to clipboardExpand all lines: docs/docs/basics-of-blazor-component-testing.md
+3-8Lines changed: 3 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,16 @@ There are three different ways of doing this in the library:
6
6
7
7
1.**C# based tests**
8
8
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**
10
10
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**
12
12
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.
13
13
14
14
In _Snapshot testing_, the rendering and verification is automatic.
15
15
16
16
For _C# based tests_ and _Razor based tests_, we have the following concepts to help us render our components and markup fragments:
17
17
18
18
-`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.
20
19
21
20
And the following concepts to help us access the rendered markup and component:
22
21
@@ -26,8 +25,4 @@ And the following concepts to help us access the rendered markup and component:
26
25
27
26
-`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.
28
27
29
-
The diagram below shows the four interfaces, their relationships to each other, and available methods.
30
-
31
-

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.
Copy file name to clipboardExpand all lines: docs/docs/creating-a-new-bunit-xunit-project.md
+20-8Lines changed: 20 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,33 @@
1
-
# Creating a new test project
1
+
# Creating a new bUnit with xUnit test project
2
2
3
3
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:
4
4
5
-
```
6
-
dotnet new --install bunit.template::1.0.0-beta-6
5
+
```bash
6
+
dotnet new --install Razor.Components.Testing.Library.Template::#{VERSION}#
7
7
```
8
8
9
9
Then to create a new project, use the following command:
10
10
11
-
```
12
-
dotnet new bunit -o <NAME OF PROJECT>
11
+
```bash
12
+
dotnet new razortest -o <NAME OF TEST PROJECT>
13
13
```
14
14
15
15
where `-o <NAME OF PROJECT>` is used to name the test project.
16
16
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
+
17
31
## Creating a new Blazor test project manually
18
32
19
33
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
0 commit comments