选择正确的测试项目
| 你要测试… | 使用项目 |
|---|---|
| 领域逻辑 / 值对象 | BitzOrcas.Unit.Tests |
| Mediator 处理器 / 管道行为 | BitzOrcas.Application.Tests |
| 带数据库的完整端点 | BitzOrcas.Integration.Tests |
| 模块边界 / DI 规则 | BitzOrcas.Architecture.Tests |
单元测试模式
public class NoteTests{ [Fact] public void Create_WithValidData_ShouldSucceed() { var note = new Note("Title", "Content"); note.Title.ShouldBe("Title"); note.DomainEvents.ShouldHaveSingleItem(); }}集成测试模式
public class NoteEndpointTests : IClassFixture<CustomWebApplicationFactory>{ private readonly HttpClient _client;
public NoteEndpointTests(CustomWebApplicationFactory factory) { _client = factory.CreateClient(); }
[Fact] public async Task GetNotes_Returns200() { var response = await _client.GetAsync("/api/notes"); response.StatusCode.ShouldBe(HttpStatusCode.OK); }}架构测试模式
[Fact]public void Domain_ShouldNotDependOnInfrastructure(){ var domain = Types.InAssembly(domainAssembly); var infra = Types.InAssembly(infrastructureAssembly);
var result = domain.ShouldNot() .HaveDependencyOnAny(infra.Types) .GetResult();
result.IsSuccessful.ShouldBeTrue();}