Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workarounds
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 83/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với trang Known problems and workarounds hoặc tài liệu về đầu ra của TestContext, sau đó xem cuộc thảo luận NUnit và issue của framework được liên kết để hiểu hành vi và các điểm cần lưu ý. Thêm một phần giải thích vì sao đầu ra từ các trình xử lý yêu cầu ASP.NET Core không được ghi lại, mô tả các cách khắc phục bằng logger và execution context, đồng thời nêu giới hạn của [OneTimeSetUp]. Hoàn tất khi người đọc có thể xác định nguyên nhân và chọn cách khắc phục.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Console.WriteLine and TestContext.Out writes made inside an ASP.NET Core request handler during a WebApplicationFactory integration test do not appear in test output. This is a common setup and the failure is silent. Nothing in the docs explains why or what to do. The only WebApplicationFactory mention is a testhost.deps.json tip in the .NET Core getting-started page.
Evidence
nunit/nunit#5067 Console.WriteLine not showing up from AspNetCore http handler (2024, 8 comments, repro in nunit/nunit.issues Issue4860):
- @manfred-brands' explanation: the controller runs on Kestrel's own thread/async context, and the test talks to it over HTTP, so there is no shared execution context and NUnit's per-test
TestExecutionContextis not present where the output is written. - A community package, agoda-com/NUnit.KestrelLogging, captures the
TestExecutionContextwhen the factory is created and restores it in the pipeline. - Important caveat from @manfred-brands: that approach only works when the factory is created per test (in the test body or
[SetUp]). It does not work when the factory is created in[OneTimeSetUp], because every test gets a new output writer. - Related framework issue nunit/nunit#4728.
Proposed change
Add a section to the adapter Known problems and workarounds page, or a short recipe near TestContext output docs, covering:
- The symptom: output from code running inside the hosted app is not captured.
- The cause in one paragraph: no shared execution context between the test thread and Kestrel's request threads.
- Options: use the app's
ILoggerwith a test logger provider that writes toTestContext.Progress; or restore the capturedExecutionContext/TestExecutionContextin middleware (link the community package as an example, not an endorsement). - The
[OneTimeSetUp]caveat, since that is how most people build their factory.
This is framework behavior rather than adapter behavior, so if we would rather not put it under the adapter, a "Capturing output" subsection on the TestContext page would also fit. Mentioning it there would also help with the stale TestContext content tracked in #531.
- Ngôn ngữ chính
- Dockerfile
- Star
- 601
- Fork
- 159
- Merge trung bình
- 22 giờ 18 phút
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nunit/docs
-
Document the adapter's agent output settings (AgentMode, ShowStdout, ShowStderr, StackTrace)Đang mởarea:adapter type:newpage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
type:newpage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Dependency DashboardĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 15/100
-
Move console/engine wiki to docsĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
area:docfx pri:p1 type:design
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
audacity/audacity.github.io#118 ·
-
bug improve content
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
opensafely/documentation#2102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
agentregistry-dev/website#69 ·
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
docs: add SECURITY.md vulnerability reporting policyCó thể đã có người làm @AK-Lmn đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
flisk-sh/linux2wasm#12 ·
Maintainer thường phản hồi trong vòng 1 ngày