Skip to content

目的別API使用方法(03_Tips)のコード例をJUnit 5化する - #718

Open
kumagoro1202 wants to merge 6 commits into
developfrom
junit5-docs/1-6-tips-lifecycle
Open

目的別API使用方法(03_Tips)のコード例をJUnit 5化する#718
kumagoro1202 wants to merge 6 commits into
developfrom
junit5-docs/1-6-tips-lifecycle

Conversation

@kumagoro1202

Copy link
Copy Markdown
Contributor

06_TestFWGuide/03_Tipsのコード例をJUnit 5前提へ改訂します。

  • 「テスト実行前後に共通処理を行いたい」の節を、JUnit 5のアノテーション(@BeforeEach/@AfterEach/@BeforeAll/@afterall)ベースへ改訂
  • Excelデータ取得・ThreadContext設定・トランザクション・プロパティ検証の各コード例を合成アノテーション+インジェクション方式へ書き換え
  • 「本フレームワークのクラスを継承せずに使用したい」の節は、JUnit 5用拡張機能では継承自体が不要である旨を明記した上で、委譲パターンもJUnit 5前提で維持
  • JUnit 4版(@Before/@BeforeClass等の解説、委譲例)はlegacy_junit4/へ移設

誤記修正:

  • プロパティ検証の実装例はexecute(String, Advice)を使用するため、使用クラスをHttpRequestTestSupportからBasicHttpRequestTestTemplateへ修正しました(旧例の継承クラスにはexecute(String, Advice)が存在せずコンパイルできない状態でした)。

マージ順序について: 本PRはスタックPRであり、先行PR 1-5(junit5-docs/1-5-download-samples)までの内容を含みます。マージ順序は 1-1 → 1-2 → 1-3 → 1-4 → 1-5 → 1-6 → 1-7 → 1-8 を厳守してください。先行PRがマージされるまで、本PRの差分表示には先行PR分の変更が含まれます。

kumagoro1202 and others added 6 commits July 10, 2026 15:05
- 06_TestFWGuide の toctree で JUnit 5用拡張機能のページを概要の直後へ移動
- 01_Abstract の特徴「JUnit4ベース」を「JUnit 5で利用可能(推奨)+JUnit 4資産と互換」へ改訂
- 01_Abstract のテストメソッド記述方法を JUnit 5(org.junit.jupiter.api.Test)ベースへ更新
- テスティングフレームワークの入口ページに新規プロジェクト/既存プロジェクトの分岐案内を追加
- 昇格に合わせて JUnit5_Extension のページ題名を「JUnit 5での利用方法」へ変更

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- 05_UnitTestGuide/legacy_junit4: JUnit 4版コード例の入口ページを新設
- 06_TestFWGuide/legacy_junit4: JUnit 4での利用方法(継承モデルの書き方・
  テスト種別と継承クラスの対応表)を新設
- 両セクションを各ガイドの toctree に追加
- 入口ページの既存プロジェクト向け案内を legacy_junit4 セクションへ誘導

既存のJUnit 4記述の本体は、各ページのJUnit 5化と合わせて順次本セクションへ
移設する(本コミットは骨格の新設のみ)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- 05_UnitTestGuide/01_ClassUnitTest 配下のコード例をJUnit 5
  (@EntityTest/@DbAccessTest合成アノテーション+インジェクション方式)へ書き換え
  - Bean Validation対応Form/Entityクラス単体テスト
  - Nablarch Validation対応Form/Entityクラス単体テスト
  - Action/Componentクラス単体テスト
- 従来のJUnit 4版(継承モデル)の3ページを legacy_junit4/ 配下へ移設
  (ラベルにlegacy_junit4接頭辞を付与し、画像は既存ディレクトリを参照、
  ダウンロード資材はlegacy側へ複製して自己完結化)
- 各標準ページの冒頭にJUnit 4版への案内を追加

コード例のAPI(合成アノテーション+フィールドインジェクション+supportメソッド呼び出し)は
nablarch-testing-junit5:2.1.0 に対して動作検証済み。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- 02_RequestUnitTest(ウェブ/REST/バッチ/メッセージング各方式)と
  03_DealUnitTest(バッチ/メッセージング)のコード例を、JUnit 5の
  合成アノテーション+インジェクション方式へ書き換え
  - ウェブ: @BasicHttpRequestTest(baseUri=...)(getBaseUriオーバーライドを置換)
  - REST: @RestTest/@SimpleRestTest(protectedメソッドはpublic版
    readTextResource(Class, String)の使用を案内)
  - バッチ: @BatchRequestTest、メッセージング: @MessagingRequestTest/
    @MessagingReceiveTest
- JUnit 4版のテストクラス宣言パターン集を legacy_junit4/04_requestUnitTest として新設
- 誤記修正: MessagingRequestTestSupportのFQCNを実際のパッケージ
  (nablarch.test.core.messaging)に合わせて修正(旧記載はnablarch.test.core.http)
- 誤記修正: 取引単体テスト(バッチ)のBatchRequestTestSupportのimport文の
  パッケージをnablarch.test.core.batchへ修正

コード例のAPIは nablarch-testing-junit5:2.1.0 に対して動作検証済み
(no-arg execute()のテスト名解決は2.1.0のTestEventDispatcherExtensionの
実装で確認)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- SystemAccountEntityTest.java / UserRegistrationFormTest.java /
  UserComponentTest.java を、JUnit 5の合成アノテーション
  (@EntityTest/@DbAccessTest)+インジェクション方式へ書き換え
  (ダウンロードURLは維持。JUnit 4版はlegacy_junit4/_download配下で提供継続)
- 誤記修正: SystemAccountEntity.javaのパッケージ宣言を、ページ本文・
  テストクラスと整合するnablarch.sample.management.userへ修正
  (旧宣言nablarch.sample.ss11.entityではテストクラスとコンパイル不能だった)

検証:
- UserRegistrationFormTest: nablarch-testing-junit5:2.1.0環境で実行し、
  JUnit 4版と実行結果が完全一致することを確認(挙動保存の確認)
- SystemAccountEntityTest / UserComponentTest: テスト対象クラス(Nablarch 5系
  サンプルアプリ資材)をスタブ化した上で、テストクラス側のAPI使用を
  nablarch-testing 6u3 + nablarch-testing-junit5:2.1.0に対してコンパイル検証

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- テスト前後の共通処理の節をJUnit 5のアノテーション
  (@BeforeEach/@AfterEach/@BeforeAll/@afterall)ベースに改訂
- Excelデータ取得・ThreadContext設定・トランザクション・委譲・
  プロパティ検証の各コード例を合成アノテーション+インジェクション方式へ書き換え
- 「継承せずに使用したい」の節は、JUnit 5用拡張機能では継承が不要である旨を
  明記した上で、委譲パターンもJUnit 5前提で維持
- JUnit 4版(@Before/@BeforeClass等の解説・委譲例)は
  legacy_junit4/01_tips_junit4 へ移設
- 誤記修正: プロパティ検証の実装例はexecute(String, Advice)を使用するため、
  使用クラスをHttpRequestTestSupportからBasicHttpRequestTestTemplateへ修正
  (旧例の継承クラスにはexecute(String, Advice)が存在せずコンパイル不能だった)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant