Upgrade to Pro — share decks privately, control downloads, hide ads and more …

e2e_design.pdf

Avatar for fumiyaki fumiyaki
March 29, 2024
170

 e2e_design.pdf

Avatar for fumiyaki

fumiyaki

March 29, 2024
Tweet

Transcript

  1. @fumiyaki 福岡県に住むフロントエンドが大好きなフロントエンジニア 趣味: ボルダリング,スノーボード,旅行,アニメ (注)x だけ@fumiyaki_です fumiya だと基本 username が取られているので

    ki をつけたのに, x.com だと既に取られていました(´;ω;`) E2E テストを導入した時に考えた設計と実装と運用について | Offers Tech Blog https://zenn.dev/overflow_offers/articles/20231024design_impl_and_ops_guess_put_e2 e_test 設計カンファレンス extends OOC 自己紹介 2
  2. 15

  3. 単体テストを厚く多く,E2E テストを最小限に留める バックエンドだと良い配分 フロントエンドでいう単体テストとは? Button や Text などの atom レベルの

    Component をテストするのだろうか? 複数の Component を使った Component は結合テストになるのだろうか? hooks で切り出した関数のテストをしたら良いのか? スナップショットテストや VRT を用いて TDD…?(いやそもそも変更検知用だし…) Testing Pyramid はフロントエンドだと良い戦略ではない 設計カンファレンス extends OOC テスト戦略 / Testing Pyramid 16
  4. 18

  5. Visual regression test UI の見た目の変更を検知 意図しない変更・波及を検知 テストの実行が低速 目的 デグレ検知 導入時期

    α バージョンリリース後 設計カンファレンス extends OOC テスト戦略 / Testing Trophy の具体 / 単体テスト 28
  6. Storybook Play Function(おすすめ) or React Testing Library バリデーションが設定された Component で,エンドユーザーに操作ミスを伝えるメッセー

    ジが表示されるかをテスト 条件付きレンダリングをテスト 目的 条件付きレンダリング,バリデーション,エラーハンドルが正しく動作しているかを確認 導入時期 プロジェクト初期がベスト 設計カンファレンス extends OOC テスト戦略 / Testing Trophy の具体 / 結合テスト 32
  7. テスト戦略まとめ フロントエンドでは Testing Pyramid より Testing Trophy が適している サービスを常に提供し続けるために,保守運用が楽なものは初期から導入して, α

    バージョンが完成後,適宜デグレを防ぐために対策を打っていく必要がある 設計カンファレンス extends OOC テスト戦略 35
  8. Page Locator Book のススメ ページ内の目当てまでの経路をページ毎に作成 メンバー変数はページが表示している Element までの経路を保持する 必要最低限のメンバー変数を実装する(頑張りすぎない) メソッドは実装しない

    メンバー変数名はページのどの部分を示すのか分かりやすく命名する header_menu_login_link main_contents_list_delete_button main_contents_card_add_button 設計カンファレンス extends OOC E2E テストの設計 / 戦術的設計 47
  9. export class TopPageLocatorBook { private readonly page: Page; private readonly

    url: string; public readonly header_menu_login_link: Locator; public readonly main_contents_list_delete_button: Locator; public readonly modal_confirm: Locator; public readonly modal_confirm_ng_button: Locator; public readonly main_contents_card_add_button: Locator; constructor(page: Page) { this.page = page; this.url = "/top"; this.header_menu_login_link = this.page .locator("header") .locator("menu") .locator("li") .getByRole("link", { name: " ログイン", }); this.main_contents_list_delete_button = this.page .getByRole("main") .locator("list") .first() .getByRole("button", { name: " 削除" }); this.modal_confirm = this.page.locator(".modal .confirm"); this.modal_confirm_ng_button = this.page .locator(".modal .confirm .ng") .getByRole("button", { name: " キャンセル" }); this.main_contents_card_add_button = this.page .locator("main .contents") .first() .locator(".card button"); } } 設計カンファレンス extends OOC E2E テストの設計 / 戦術的設計 / Page Locator Book のススメ 48
  10. test(` アイテムを追加して,リストアイテムを削除しようとして思いとどまるシナリオ`, async ({ page, }) => { const topPage

    = new TopPageLocatorBook(page); await page.goto(topPage.url); await topPage.main_contents_card_add_button.click(); await topPage.main_contents_list_delete_button.click(); expect(topPage.modal_confirm).toBeVisible(); await topPage.modal_confirm_ng_button.click(); expect(topPage.modal_confirm).not.toBeVisible(); }); 設計カンファレンス extends OOC E2E テストの設計 / 戦術的設計 / Page Locator Book のススメ 50
  11. Page Locator Book のススメ まとめ テスト実装時,ユーザーのインタラクションに集中してテストが書けるようになる テスト修正時,ロケーションは 1 箇所に集まっているので修正時に楽 テスト修正時,(命名センスに依存してしまうが…)ストーリーを追いやすい

    テスト修正時,Locator book とシナリオに分離されているので目が滑りにくい 複雑な事はしていないのでシンプルで始めやすい 設計カンファレンス extends OOC E2E テストの設計 / 戦術的設計 51
  12. 54

  13. 55

  14. 56