This document outlines the coding standards, guidelines, and best practices for contributing to the bUnit project.
bUnit is a testing library for Blazor Components that runs on top of existing unit testing frameworks (xUnit, NUnit, MSTest, TUnit). The goal is to write comprehensive, stable unit tests that run in milliseconds.
- C# Language Version: Use
previewfeatures as defined inDirectory.Build.props - Nullable Reference Types: Always enabled - use nullable annotations appropriately
- Implicit Usings: Enabled - common namespaces are automatically imported
- Use tabs for indentation (not spaces)
- Tab width: 4 spaces
- Charset: UTF-8
- Always trim trailing whitespace (except in .md files)
- Insert final newline in all files
- Use
varfor built-in types and when type is apparent - Prefer expression-bodied members for single-line methods, properties, and accessors
- Use pattern matching over
aswith null check andiswith cast check - Prefer object and collection initializers
- Use language keywords instead of framework type names (e.g.,
intnotInt32) - Always use braces for code blocks (even single-line if statements)
- Prefer
nullpropagation and coalesce expressions - Use file-scoped namespaces (C# 10+)
- Place using directives outside namespace
- PascalCase: Classes, interfaces (with
Iprefix), methods, properties, events, enums, delegates, namespaces - camelCase: Private fields, local variables, parameters
- Static readonly fields: PascalCase
- Constants: PascalCase
- Generic type parameters: PascalCase with
Tprefix - No public/protected instance fields - use properties instead
- Always specify accessibility modifiers explicitly
- Order:
public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
- Always build in RELEASE mode for validation:
dotnet build -c Release - All warnings are treated as errors in Release configuration
- Projects must be signed with strong name (
key.snk) - Enable all analyzers:
AnalysisModeis set toAllEnabledByDefault
- All tests must pass before submitting changes
- Run tests in Release mode:
dotnet test -c Release --no-restore - Tests must be provided for every bug fix and feature
- Test projects can use relaxed analyzer rules (see
tests/**/.editorconfig) - Tests should be specific to the changes being made
- Support for multiple test frameworks: xUnit, NUnit, MSTest, TUnit
Before submitting any changes, ensure:
dotnet restorecompletes successfullydotnet build -c Releasecompletes without warnings or errorsdotnet test -c Releasecompletes with all tests passing- Code adheres to .editorconfig rules (enforced during build)
- Microsoft Code Analysis: Enabled with all rules
- StyleCop: Enforced via .editorconfig
- Meziantou Analyzer: Specific rules enabled
- SonarAnalyzer: Enabled with specific suppressions
- Code style violations are enforced in build (
EnforceCodeStyleInBuild: true)
- Default severity for .NET Code Style: error
TreatWarningsAsErrors: true in Release mode- Unused parameters must be removed (
IDE0060) - Unnecessary suppressions must be removed (
IDE0079)
- Follow trunk-based development - base changes on
mainbranch - Use Conventional Commits style for commit messages
feat:for new featuresfix:for bug fixesdocs:for documentation changestest:for test additions/changesrefactor:for code refactoringchore:for maintenance tasks
- Ensure repository can build successfully
- All tests must pass
- Follow existing coding conventions (aligned with ASP.NET Core team guidelines)
- PRs should be focused and specific to the issue being addressed
- Add/update tests to cover your changes
bunit- Main package with all functionalitybunit.core- Core testing functionalitybunit.web- Web-specific components testingbunit.web.query- Testing-library.com query API implementationbunit.generators- Source generatorsbunit.template- Project templates (xUnit, NUnit, MSTest)
bunit.tests- Main test suitebunit.web.query.tests- Query API testsbunit.generators.tests- Source generator testsbunit.testassets- Shared test assets
- Update relevant documentation when making changes
- Keep XML documentation comments current
- Documentation must be clear and concise
- Code examples should be tested and working
- Central Package Management is enabled (
Directory.Packages.props) - Follow semantic versioning for package references
- Minimize external dependencies
The following namespaces are automatically imported (except in template and generators projects):
Microsoft.AspNetCore.ComponentsMicrosoft.AspNetCore.Components.RenderTreeMicrosoft.AspNetCore.Components.RenderingMicrosoft.Extensions.DependencyInjectionSystem.Runtime.SerializationSystem.Diagnostics.CodeAnalysis
- Tests should run in milliseconds (not seconds)
- Avoid blocking calls in async methods
- Use
ConfigureAwait(false)where appropriate (except in test code)
- Follow the .NET Foundation Code of Conduct
- Be respectful and collaborative in all interactions
When making changes, always:
- ✅ Use tabs for indentation
- ✅ Enable nullable reference types
- ✅ Use file-scoped namespaces
- ✅ Build in Release mode (
-c Release) - ✅ Run all tests in Release mode
- ✅ Ensure no warnings (warnings = errors in Release)
- ✅ Follow naming conventions (PascalCase for public, camelCase for private)
- ✅ Add XML documentation for public APIs
- ✅ Write tests for all changes
- ✅ Use conventional commit message format
- ✅ Verify all analyzer rules pass
- ✅ Check that code compiles against all target frameworks (.NET 8, 9, 10)