eventuras-testing
Running and managing tests in the Eventuras monorepo (xUnit backend tests, Playwright E2E tests, integration tests)
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Eventuras Testing Skill
Overview
This skill provides comprehensive testing capabilities for the Eventuras monorepo, covering backend xUnit tests, frontend Playwright E2E tests, and integration testing patterns.
Backend Testing (C# .NET)
Running All Backend Tests
cd apps/api
dotnet test
Running Specific Test Project
# Unit tests
dotnet test tests/Eventuras.UnitTests
# Integration tests
dotnet test tests/Eventuras.IntegrationTests
# Web API tests
dotnet test tests/Eventuras.WebApi.Tests
Running Specific Test Class
dotnet test --filter "FullyQualifiedName~Eventuras.WebApi.Tests.EventsControllerTests"
Running Specific Test Method
dotnet test --filter "FullyQualifiedName~Eventuras.WebApi.Tests.EventsControllerTests.GetEvents_ShouldReturnOk"
Running Tests with Verbose Output
dotnet test --logger "console;verbosity=detailed"
Running Tests with Code Coverage
dotnet test /p:CollectCoverage=true /p:CoverageReportsDirectory=./coverage
Frontend E2E Testing (Playwright)
Running All E2E Tests
cd apps/web-e2e
pnpm test
Running Specific Test File
cd apps/web-e2e
pnpm playwright test playwright-e2e/admin-events.spec.ts
Running Tests in UI Mode (for debugging)
cd apps/web-e2e
pnpm playwright test --ui
Running Tests in Headed Mode
cd apps/web-e2e
pnpm playwright test --headed
Running Tests for Specific Browser
cd apps/web-e2e
pnpm playwright test --project=chromium
pnpm playwright test --project=firefox
pnpm playwright test --project=webkit
Show Test Report
cd apps/web-e2e
pnpm playwright show-report
Integration Testing
Database Setup
Integration tests use a PostgreSQL database. Connection string:
Host=localhost;Port=5432;Database=eventuras_test;Username=postgres;Password=postgres
The database is automatically configured when running in GitHub Actions environment.
Authentication in Tests
Backend integration tests use mock authentication:
// System admin
var client = _factory.CreateClient().AuthenticatedAsSystemAdmin();
// Specific user
var client = _factory.CreateClient().AuthenticatedAs(user.Entity);
// User with specific role
var client = _factory.CreateClient().AuthenticatedAs(admin.Entity, Roles.Admin);
// Generic role
var client = _factory.CreateClient().Authenticated(role: "Admin");
Frontend E2E tests use setup projects defined in playwright.config.ts:
-
admin.auth.setup.ts- Admin authentication -
user.auth.setup.ts- User authentication
Common Testing Patterns
Backend Test Structure
[Fact]
public async Task MethodName_Scenario_ExpectedBehavior()
{
// Arrange
var client = _factory.CreateClient().AuthenticatedAsSystemAdmin();
var eventData = new EventDto { /* ... */ };
// Act
var response = await client.PostAsync("/api/v3/events", eventData);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Created);
var result = await response.Content.ReadFromJsonAsync<EventDto>();
result.Should().NotBeNull();
}
Frontend E2E Test Structure
test('should create new event', async ({ page }) => {
// Arrange
await page.goto('/admin/events');
// Act
await page.getByRole('button', { name: 'New Event' }).click();
await page.getByLabel('Title').fill('Test Event');
await page.getByRole('button', { name: 'Save' }).click();
// Assert
await expect(page.getByText('Event created successfully')).toBeVisible();
});
Test Debugging Tips
Backend Tests
- Set breakpoints in Visual Studio Code or Visual Studio
- Use Test Explorer to run individual tests
- Check test output for detailed error messages
- Use
--logger "console;verbosity=detailed"for more information
Frontend E2E Tests
- Use
--uimode for interactive debugging - Use
--headedmode to see browser actions - Use
--debugflag to pause execution - Check Playwright trace files for detailed execution
- Use browser DevTools for inspecting elements
Running Tests from Monorepo Root
# Run all tests (backend + frontend)
pnpm test
# Build and test web app
pnpm --filter @eventuras/web test
# Build and test API
cd apps/api && dotnet test
CI/CD Testing
Tests run automatically in GitHub Actions:
- Backend tests run on every push
- E2E tests run on PR and main branch
- Database is automatically provisioned
- Test results are reported in PR checks
When to Run Tests
- ✅ Before committing changes
- ✅ After implementing new features
- ✅ After fixing bugs
- ✅ Before creating PRs
- ✅ After updating dependencies
- ✅ When modifying shared libraries
Test Coverage Goals
- Backend API endpoints: >80% coverage
- Business logic services: >90% coverage
- Critical user flows (E2E): 100% coverage
- Shared libraries: >85% coverage
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!