Skip to content

Commit bf9848e

Browse files
Copilotlinkdotnet
andcommitted
docs: Update README with bUnit.analyzers package information
Co-authored-by: linkdotnet <[email protected]>
1 parent 1b5514f commit bf9848e

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ bUnit is available on NuGet in various incarnations. Most should just pick the [
2323
| Name | Description | NuGet Download Link |
2424
| -------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
2525
| [bUnit](https://www.nuget.org/packages/bunit/) | Adds support for testing Blazor components. | [![Nuget](https://img.shields.io/nuget/dt/bunit?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) |
26+
| [bUnit.analyzers](https://www.nuget.org/packages/bunit.analyzers/) | Roslyn analyzers to help identify common mistakes and anti-patterns. | [![Nuget](https://img.shields.io/nuget/dt/bunit.analyzers?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.analyzers/) |
2627
| [bUnit.template](https://www.nuget.org/packages/bunit.template/) | Template, which currently creates 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/) |
2728
| [bUnit.generators](https://www.nuget.org/packages/bunit.generators/) | Source code generators to minimize code setup in various situations. | [![Nuget](https://img.shields.io/nuget/dt/bunit.generators?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.generators/) |
2829
| [bUnit.web.query](https://www.nuget.org/packages/bunit.web.query/) | bUnit implementation of testing-library.com's query APIs. | [![Nuget](https://img.shields.io/nuget/dt/bunit.web.query?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web.query/) |

src/bunit.analyzers/README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,26 @@ This package contains Roslyn analyzers for bUnit that help identify common mista
44

55
## Analyzers
66

7+
### BUNIT0002: Prefer Find<T> over casting
8+
9+
**Status**: ✅ Implemented
10+
11+
When finding elements with a specific type, use `Find<T>(selector)` instead of casting the result of `Find(selector)`.
12+
13+
**Bad:**
14+
```csharp
15+
IHtmlAnchorElement elem = (IHtmlAnchorElement)cut.Find("a");
16+
```
17+
18+
**Good:**
19+
```csharp
20+
var elem = cut.Find<IHtmlAnchorElement>("a");
21+
```
22+
723
### BUNIT0001: Razor test files should inherit from BunitContext
824

25+
**Status**: 🚧 Planned
26+
927
When writing tests in `.razor` files that use variables or event callbacks from the test code, the file must inherit from `BunitContext` using `@inherits BunitContext`. Otherwise, you may encounter the error "The render handle is not yet assigned."
1028

1129
**Bad:**
@@ -36,20 +54,6 @@ When writing tests in `.razor` files that use variables or event callbacks from
3654
}
3755
```
3856

39-
### BUNIT0002: Prefer Find<T> over casting
40-
41-
When finding elements with a specific type, use `Find<T>(selector)` instead of casting the result of `Find(selector)`.
42-
43-
**Bad:**
44-
```csharp
45-
IHtmlAnchorElement elem = (IHtmlAnchorElement)cut.Find("a");
46-
```
47-
48-
**Good:**
49-
```csharp
50-
var elem = cut.Find<IHtmlAnchorElement>("a");
51-
```
52-
5357
## Installation
5458

5559
Install the package via NuGet:
@@ -58,4 +62,8 @@ Install the package via NuGet:
5862
dotnet add package bunit.analyzers
5963
```
6064

61-
The analyzers will automatically run during compilation and provide warnings and code fixes in your IDE.
65+
The analyzers will automatically run during compilation and provide warnings in your IDE.
66+
67+
## Contributing
68+
69+
We welcome contributions! If you have ideas for additional analyzers that could help bUnit users, please open an issue or submit a pull request.

0 commit comments

Comments
 (0)