Skip to content

Commit 2132316

Browse files
committed
Updated changelog
1 parent 647b358 commit 2132316

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,117 @@ All notable changes to **bUnit** will be documented in this file. The project ad
44

55
<!-- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) -->
66

7+
## [1.0.0]
8+
9+
The following section list all changes since preview 02.
10+
11+
### Changed
12+
13+
List of changes in existing functionality.
14+
15+
- _**BREAKING CHANGE:**_ Writing tests using the test components `<Fixture>` and `<SnapshotTest>` components inside .razor files has been moved to its own library, `bunit.web.testcomponents`. This was done for several reasons:
16+
17+
- The feature has been experimental since it was introduced, and it was introduced get a more natural way of specifying the component under test and any related markup used by test.
18+
- The feature is only supported with xUnit.
19+
- There are some issues related to the `SourceFileFinder` library, which is used to discover the test components.
20+
- A better way of writing tests in .razor files has been added to bUnit, using *"inline render fragments"*. This method works with all general purpose test frameworks, e.g. MSTest, NUnit, and xUnit, is more flexible, and offer less boilerplate code than the test components. The bUnit documentation has been updated with a guide to this style.
21+
22+
The new package `bunit.web.testcomponents` is provided as is, without expectation of further development or enhancements. If you are using the test components currently for writing tests, it will continue to work for you. If you are starting a new project, or have few of these tests, consider switching to the "inline render fragments" style.
23+
24+
Here is a quick comparison of the styles, using a very simple component.
25+
26+
First, the test component style:
27+
28+
```razor
29+
@inherits TestComponentBase
30+
31+
<Fixture Test="HelloWorldComponentRendersCorrectly">
32+
<ComponentUnderTest>
33+
<HelloWorld />
34+
</ComponentUnderTest>
35+
36+
@code
37+
{
38+
void HelloWorldComponentRendersCorrectly(Fixture fixture)
39+
{
40+
// Act
41+
var cut = fixture.GetComponentUnderTest<HelloWorld>();
42+
43+
// Assert
44+
cut.MarkupMatches("<h1>Hello world from Blazor</h1>");
45+
}
46+
}
47+
</Fixture>
48+
49+
<SnapshotTest Description="HelloWorld component renders correctly">
50+
<TestInput>
51+
<HelloWorld />
52+
</TestInput>
53+
<ExpectedOutput>
54+
<h1>Hello world from Blazor</h1>
55+
</ExpectedOutput>
56+
</SnapshotTest>
57+
```
58+
59+
The a single test in "inline render fragments" style covers both cases:
60+
61+
```
62+
@inherits TestContext
63+
@code {
64+
[Fact]
65+
public void HelloWorldComponentRendersCorrectly()
66+
{
67+
// Act
68+
var cut = Render(@<HelloWorld />);
69+
70+
// Assert
71+
cut.MarkupMatches(@<h1>Hello world from Blazor</h1>);
72+
}
73+
}
74+
```
75+
76+
To make the snapshot test scenario even more compact, consider putting all code in one line, e.g. `Render(@<HelloWorld />).MarkupMatches(@<h1>Hello world from Blazor</h1>);`.
77+
78+
For a more complete snapshot testing experience, I recommend looking at Simon Cropp's [Verify](https://github.com/VerifyTests) library, in particular the [Verify.Blazor extension to bUnit](https://github.com/VerifyTests/Verify.Blazor#verifybunit). Verify comes with all the features you expect from a snapshot testing library.
79+
80+
### Removed
81+
82+
List of now removed features.
83+
84+
- The `AddXunitLogger` method, which provided support for capturing `ILogger` messages and passing them to xUnit's `ITestOutputHelper`, has been removed. There were no need to keep xUnit specific code around in bUnit going forward, and there are many implementations on-line that supports this feature, so having it in bUnit made little sense. One such alternative, which bUnit has adopted internally, is to use Serilog. This looks as follows:
85+
86+
1. Add the following packages to your test project: `Serilog`, `Serilog.Extensions.Logging`, and `Serilog.Sinks.XUnit`.
87+
2. Add the following class/extension method to your test project (which replicates the signature of the removed `AddXunitLogger` method):
88+
89+
```csharp
90+
using Microsoft.Extensions.DependencyInjection;
91+
using Microsoft.Extensions.Logging;
92+
using Serilog;
93+
using Serilog.Events;
94+
using Xunit.Abstractions;
95+
96+
namespace Bunit
97+
{
98+
public static class ServiceCollectionLoggingExtensions
99+
{
100+
public static IServiceCollection AddXunitLogger(this IServiceCollection services, ITestOutputHelper outputHelper)
101+
{
102+
var serilogLogger = new LoggerConfiguration()
103+
.MinimumLevel.Verbose()
104+
.WriteTo.TestOutput(outputHelper, LogEventLevel.Verbose)
105+
.CreateLogger();
106+
107+
services.AddSingleton<ILoggerFactory>(new LoggerFactory().AddSerilog(serilogLogger, dispose: true));
108+
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
109+
110+
return services;
111+
}
112+
}
113+
}
114+
```
115+
116+
- The `bunit.xunit` package has been removed, since it is no longer needed (there is no code left in it).
117+
7118
## [1.0.0-preview-02] - 2021-03-26
8119

9120
The following section list all changes in 1.0.0 preview 02.

0 commit comments

Comments
 (0)