Demo1.PlaywrightTestsprovides headless smoke coverage using Playwright against a running instance of the site.
- Create a test project (e.g.,
Demo1.Tests):dotnet new xunit -n Demo1.Tests dotnet add Demo1.Tests/Demo1.Tests.csproj reference Demo1/Demo1.csproj
- Add tests for controllers and services.
- Update the solution file to include the test project:
dotnet sln add Demo1.Tests/Demo1.Tests.csproj
- Locally:
dotnet test - Playwright browsers (first run):
dotnet build tests/Demo1.PlaywrightTestsfollowed bypwsh bin/Debug/net9.0/playwright.ps1 installor simply execute the tests once and the suite will install browsers automatically. - CI (GitHub Actions): Automatically installs Playwright via
Microsoft.Playwright.CLIand runsdotnet testwhen test projects exist.
- Use AAA (Arrange-Act-Assert) pattern.
- Mock dependencies (e.g.,
ILogger<T>, services) where appropriate. - Keep tests deterministic and isolated.