Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workarounds
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 83/100
- issue の種類
- ドキュメント
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- csharp
調査の方向性
Known problems and workarounds ページまたは TestContext の出力に関するドキュメントから始め、リンクされている NUnit の議論とフレームワークの issue を確認して、動作と注意点を把握します。ASP.NET Core のリクエストハンドラーからの出力がキャプチャされない理由を説明し、logger と実行コンテキストを使った回避策を記述して、[OneTimeSetUp] の制限を含むセクションを追加します。読者が原因を特定し、回避策を選べるようになれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Dockerfile
- スター
- 601
- フォーク
- 159
- 平均マージ
- 22時間 18分
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nunit/docs のほかの issue
-
area:adapter type:newpage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
type:newpage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
Dependency Dashboardオープン
難易度 3/5 1〜2日 初心者へのやさしさ 15/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
area:docfx pri:p1 type:design
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
audacity/audacity.github.io#118 ·
-
bug improve content
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
opensafely/documentation#2102 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
agentregistry-dev/website#69 ·
-
15.0
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
docs: add SECURITY.md vulnerability reporting policy対応中かも @AK-Lmn が今日担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
flisk-sh/linux2wasm#12 ·
メンテナーはふだん 1 日以内に返信