|
1 | | -[](https://github.com/egil/bunit) |
| 1 | +[](https://github.com/egil/bunit/actions?query=workflow%3ACI) |
2 | 2 | [](https://github.com/egil/bunit/releases) |
3 | 3 | [](https://www.nuget.org/packages/bunit/) |
4 | | -[](https://gitter.im/egil/bunit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) |
5 | | -[](https://github.com/egil/bunit/actions?query=workflow%3ACI) |
6 | 4 | [](https://github.com/egil/bunit/issues) |
| 5 | +[](https://gitter.im/egil/bunit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) |
| 6 | + |
| 7 | +# bUnit - a testing library for Blazor components |
| 8 | + |
| 9 | +**bUnit** is a testing library for Blazor Components. You can: |
| 10 | + |
| 11 | +- Setup and define components under tests in C# or Razor syntax |
| 12 | +- Verify outcome using semantic HTML diffing/comparison logic |
| 13 | +- Interact with and inspect components |
| 14 | +- Trigger event handlers |
| 15 | +- Provide cascading values |
| 16 | +- Inject services |
| 17 | +- Mock `IJsRuntime` |
| 18 | +- Perform snapshot testing |
| 19 | + |
| 20 | +The library builds on top of existing unit testing frameworks such as xUnit, which runs the Blazor components tests, just as any normal unit test. |
| 21 | + |
| 22 | +The library's goal is to make it easy to write _comprehensive, stable unit tests_ for Blazor Components/Razor Components. |
| 23 | + |
| 24 | +For example, to test the [`Counter.razor`](https://github.com/egil/bunit/blob/master/sample/src/Pages/Counter.razor) component that is part of the Blazor "file-new-project" project, you can do the following, using bUnit and xUnit: |
| 25 | + |
| 26 | +```csharp |
| 27 | +[Fact] |
| 28 | +public void CounterShouldIncrementWhenClicked() |
| 29 | +{ |
| 30 | + // Arrange: render the Counter.razor component |
| 31 | + var cut = RenderComponent<Counter>(); |
| 32 | + |
| 33 | + // Act: find and click the <button> element to increment |
| 34 | + // the counter in the <p> element |
| 35 | + cut.Find("button").Click(); |
| 36 | + |
| 37 | + // Assert: first find the <p> element, then verify its content |
| 38 | + cut.Find("p").MarkupMatches("<p>Current count: 1</p>"); |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +**Go to [Documentation](/docs) to learn more.** |
| 43 | + |
| 44 | +## Milestones to v1.0.0 |
7 | 45 |
|
8 | | -# bUnit - a testing library for Blazor Components |
| 46 | +These are the current goals that should be reached before v1.0.0 is ready: |
9 | 47 |
|
10 | | -**bUnit**, previously known as **Blazor Components Testing Library**, is a unit testing library for Blazor Components. You can easily define components under test in C# or Razor syntax, and verify outcome using semantic HTML diffing/comparison logic. You can interact with and inspect components, trigger event handlers, provide cascading values, inject services, mock IJsRuntime, and perform snapshot testing. |
| 48 | +- **Stabilize the APIs**, such that they work equally well with both xUnit, Nunit, and MSTest as the underlying test framework. The general goals is to make it easy and obvious for developers to create the tests they needed, and fall into the pit of success. |
| 49 | +- **Get the Razor-based testing to stable**, e.g. make the discovery and running of tests defined in .razor files stable and efficient. This includes adding support for Nunit and MSTest as test runners. |
| 50 | +- **Improve the documentation**. Currently there are a list of "How to" guides planned in the [Update Docs](https://github.com/egil/bunit/issues?q=is%3Aopen+is%3Aissue+milestone%3A%22updated+docs%22) milestone. |
| 51 | +- **Join the .NET Foundation.**. This project is too large for one person to be the owner and be the sole maintainer of, so the plan is to apply for membership as soon as possible, most likely close to or after v1.0.0 ships, and get the needed support and guidance to ensure the project long term. |
11 | 52 |
|
12 | | -This library's goal is to make it easy to write _comprehensive, stable unit tests_ for Blazor Components/Razor Components. To see how, go to the [Documentation pages](/docs). |
| 53 | +In the post v1.0.0 to v1.0.x time frame, focus will be on improving performance. Especially the spin-up time of about one second would be nice to get reduced. |
13 | 54 |
|
14 | | -To browse the source code and provide feedback, head to https://github.com/egil/bunit/. |
| 55 | +## Contributors |
15 | 56 |
|
16 | | -### Contributors |
| 57 | +Shout outs and a big thank you [to all the contributors](https://github.com/egil/bunit/graphs/contributors) to the library, both those that raise issues, provide input to issues, and those who send pull requests. |
17 | 58 |
|
18 | | -Shout outs and a big thank you to the contributors to this library. Here they are, in alphabetically: |
| 59 | +**Want to help out? You can help in a number of ways:** |
19 | 60 |
|
20 | | -- [Michael J Conrad (@Siphonophora)](https://github.com/Siphonophora) |
21 | | -- [Rastislav Novotný (@duracellko)](https://github.com/duracellko) |
| 61 | +- Provide feedback and input through [issues](https://github.com/egil/bunit/issues), [Twitter](https://twitter.com/egilhansen) or [bUnit Gitter chat room](https://gitter.im/egil/bunit). |
| 62 | +- Help build the library, just pick an issue and submit pull-requests. |
| 63 | +- Help write documentation. |
| 64 | +- Create blog posts, presentations or video tutorials. If you do, I will be happy to showcase them in the related section on this site. |
0 commit comments