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

ユニットテスト初心者を脱するために身につけたいN個のこと / N points to get out of unit test beginner #phpstudy

ユニットテスト初心者を脱するために身につけたいN個のこと / N points to get out of unit test beginner #phpstudy

ユニットテスト初心者を脱するために身につけたいN個のこと / N points to get out of unit test beginner #phpstudy

https://docs.google.com/presentation/d/1FAhVfOakoUTguKYuM9VYU_Vb88VaU5aKpGUeXST6rqg/edit?usp=sharing

Kazuki Higashiguchi

February 27, 2019
Tweet

More Decks by Kazuki Higashiguchi

Other Decks in Technology

Transcript

  1. @hgsgtk Kazuki Higashiguchi job is … Software Engineer lang is

    ... PHP, Go ...etc belongs to ... BASE BANK株式会 社 (BASE株式会社の100%子会社) at #phpstudy talked about … CakePHP4.x / terraform / ECS / Unit Testing 7
  2. = 1. What is Unit testing? 2. Learn useful functions

    of PHPUnit 3. Clarify the intent of the test 4. Tear down completely 9 N=0; N++;
  3. = ソフトウェアにまつわる様々なテスト • 単体テスト(Unit Testing) • 結合テスト(Integration Testing) • システムテスト(System

    testing) • 運用テスト(Implementation Testing) • 障害テスト(Recovery Testing) • 耐久テスト(Duration Testing) • パフォーマンステスト(Performance Testing) 11 Software Testing ways
  4. Unit Testing ~ One of Testing ways ~ 12 WHAT

    • Unit = アプリケーションのテスト可能な 最小の部品単位 • クラス・メソッドに対するテスト • 主にプログラマによって作成される WHY • バグを見つける • テスト対象のドキュメンテーション • 設計の欠陥を明らかにする ...etc
  5. Testing Framework ユニットテストの方法 13 • PHPUnit ◦ https://phpunit.de/ ◦ PHPUnit

    is a programmer-oriented testing framework for PHP. ◦ xUnit architecture • composer require --dev phpunit/phpunit ^7
  6. = • xUnit Architecture ◦ https://en.wikipedia.org/wiki/XUnit ◦ https://www.martinfowler.com/bliki/Xunit.html ◦ All

    xUnit frameworks share the following basic component architecture • basic components ◦ Test Runner ◦ Test Case ◦ Test Fixtures ◦ Test Suites ◦ Test Execution (setup / teardown) ◦ Test Result Formatter ◦ Assertions 14 xUnit architecture
  7. = • setUp / tearDown ◦ テストクラス共通の前準備・後片付けを定義する • assertEquals /

    assertSame ◦ 値比較 • @expectedException and @expectedExceptionMessage ◦ Exceptionのアサーション • @dataProvider ◦ テストケースをテストメソッドから分離 17 basic functions of PHPUnit
  8. assertSame / assertEquals 19 • differences ◦ assertEquals => ‘==’

    ◦ assertSame => ‘===’ • assertSame is stricter.
  9. テストケース名を 明確に • 「どういうケースなのか」 を明確に • 場合によっては、日本語の テストケース名もOK 26 •

    dataProviderのキー名にケース名を指定 • テスト実行時に指定したキー名をPHPUnitが認識する
  10. = • Testing the function that contains external service •

    Test Driven Development • Test Coverage • Sprout class/method ...etc 32 N++;