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

フロントエンドテストプラクティス in open 8

フロントエンドテストプラクティス in open 8

2021/09/13

Open8 で発表したフロントエンドテストプラクティスの話です。

Yosuke Furukawa

September 13, 2021
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. ςετ = ମॏܭ • ͜ͷϝλϑΝʔΛ͏·͘ҙࣝ͢Δͱ৭ʑཧղ͠΍͍͢ • QA = ਓؒυοΫ •

    ຖ೔ਓؒυοΫʹߦͬͯຖ೔ϝσΟΧϧνΣοΫΛड ͚Δਓ͸͍ͳ͍ • ମॏܭʹ৐ͬͨΓɺ݂ѹܭͰଌͬͨΓ͢Δ͘Β͍͕ຖ ೔΍Δ͜ͱͱͯ͠ஸ౓͍͍ൣғͩͬͨΓ͢Δ
  2. ϑϩϯτΤϯυςετ • Ϣχοτςετ • ݁߹ςετ • E2Eςετ • a11yςετ •

    ύϑΥʔϚϯεςετ • ϏδϡΞϧϦάϨογϣϯςετ
  3. Ϣχοτςετ • ୯ମͷίϯϙʔωϯτɺٴͼ୯Ұػೳͷؔ਺ ͷ in / out ΛνΣοΫ͢Δςετ function doSomething(name)

    { if (name) { return name; } return "no name"; } // ୯ମςετ෦෼ test("doSomething", () => { assert("test", doSomething("test")); });
  4. ݁߹ςετ • "୯ମ"Λ௒͑ͯෳ਺ͷίϯϙʔωϯτΛ૊Έ߹ Θͤͨςετͷ͜ͱ export const Greeting = () =>

    { const [showGreeting, setShowGreeting] = useState(false); return ( <div> <p data-testid="greeting">{showGreeting && sayHello()}</p> <button data-testid="show-greeting-button" onClick={() => setShowGreeting(true)}>Show Greeting</ button> </div> ); }; test('shows correct greeting', () => { const screen = render(<Greeting />); const greeting = screen.getByTestId('greeting'); const button = screen.getByTestId('show-greeting- button'); expect(greeting.textContent).toBe(''); fireEvent.click(button); expect(greeting.textContent).toBe('Hello human!'); });
  5. ͲΕ͘Β͍ͷׂ߹Ͱ΍Δͷ͕͍ ͍͔ʁ • Google ͸ • 10% E2E • 20%

    Integration • 70% Unit • ͱ͍͏ϐϥϛουΛܗ੒ͯ͠Δ https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html
  6. Why a11y tests? • test ͡Όͳͯ͘ lint ͕ͩɺ accesslint ΍

    axe- core(LH͕தͰ࢖ͬͯΔ΍ͭ) ͱ͔ͷνΣοΫ πʔϧ΋͋Δ
  7. Why ύϑΥʔϚϯεςετ? • ύϑΥʔϚϯεʹؔ͢Δ΋ͷ΋࣮ࡍ͸ଟذʹΘͨΔ • όϯυϧαΠζ • ϖʔδಡΈࠐΈ࣌ؒ • ը૾αΠζ

    • ͳͲͳͲ • ͜ΕΒͷཁҼΛ·Δͬͱ͍͍ײ͡ʹධՁͯ͘͠ΕΔͷ͕Core Web Vitals • ҰํͰύϑΥʔϚϯε΋ຊདྷ͸໨త͕͋ΔͷͰࣗ෼ͨͪͰKPIΛ࡞ͬͯݕূΛ ࣮ࢪ͢Δͷ͕ϕετɻ
  8. ϏδϡΞϧϦάϨογϣϯςε τ • Ͳͷ͘Β͍ͷཻ౓Ͱ΍Δͱ͍͍ͷ͔ʁ • StoryBook ͰίϯϙʔωϯτΛ·ͱΊΔ͜ͱ͕͋Δͱࢥ͏͕ɺͦͷ୯ Ґ͘Βׂ͍͕ͱྑ͍ɻ • ཻ౓͕େ͖͍ͱ৭Μͳෆ֬ఆཁૉ͕བྷΉͷͰɺςετ͕

    flaky ʹͳΓ͕ ͪ • ฐࣾͩͱ׬શʹίϯϙʔωϯτ୯ҐͰ StoryBook Λ࡞Γͳ͕Βɺ reg- suit ͱ૊Έ߹ΘͤͯσβΠϯ่ΕΛࣄલݕ஌͍ͯ͠Δ • StoryBook ۦಈ։ൃͱ͔ݺ͹ΕͯΔɻ
  9. ςετϕετϓϥΫςΟε • ϢχοτςετͱΠϯςάϨʔγϣϯςετ͸ؤுͬͯॻ͍͓ͯ ͘ɻ • E2E͸Ұ൪ҰൠతͳϩάΠϯ͔ͯ͠Β࠷ॳͷϖʔδϙνϙν͢Δ ͘Β͍·Ͱ͸΍Γ͍ͨɻ • a11y /

    performance ͸Lighthouseͱ͔Ͱ࠷ॳ͸ΧδϡΞϧʹɺ ঃʑʹࣗ෼ͨͪͷ໨తʹ߹Θ͍ͤͯ͘ • VRT ͸ StoryBook ϕʔεͰ࣮ࢪͭͭ͠ɺ͜Ε΋໨తʹ߹Θͤͯ૿ ΍͍ͯ͘͠