Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
自作してみようxUnitフレームワーク / try-to-self-made-xunit
Search
Kazuki Higashiguchi
December 01, 2019
Technology
0
1.5k
自作してみようxUnitフレームワーク / try-to-self-made-xunit
PHPカンファレンス2019にて発表する懇親会LTの資料です
Kazuki Higashiguchi
December 01, 2019
Tweet
Share
More Decks by Kazuki Higashiguchi
See All by Kazuki Higashiguchi
インフラコストとセキュリティ課題解決のためのリアーキテクチャリング / srekaigi2025
hgsgtk
3
4.9k
Design of a Stateful system for Robust Deployment and Observability
hgsgtk
0
1.2k
A guide to joining operational work in your new DevOps team
hgsgtk
1
1.4k
HTTP Tunneling in Go
hgsgtk
0
1.4k
ブラウザ自動操作技術の深層へ、直接触れて学ぶ WebDriver と Chrome DevTools Protocol
hgsgtk
3
6.5k
HTTP Server on random available port in Go
hgsgtk
0
980
Agile Testingを夢見たテスト自動化 〜ATDDへの挑戦から始まる 1年間の試行錯誤〜 / dreaming agile testing at basebank
hgsgtk
14
7.8k
Create Go WebDriver client from scratch
hgsgtk
1
2.2k
PHPでWeb Driver Clientを自作する〜己の手でブラウザ操作自動化を完全理解する方法〜 / phpcon2021
hgsgtk
2
2.5k
Other Decks in Technology
See All in Technology
脳波を用いた嗜好マッチングシステム
hokkey621
0
170
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
17
45k
Tech Blogを書きやすい環境づくり
lycorptech_jp
PRO
1
260
ESXi で仮想化した ARM 環境で LLM を動作させてみるぞ
unnowataru
0
130
Amazon S3 Tablesと外部分析基盤連携について / Amazon S3 Tables and External Data Analytics Platform
nttcom
0
150
2.5Dモデルのすべて
yu4u
2
930
Share my, our lessons from the road to re:Invent
naospon
0
110
管理者しか知らないOutlookの裏側のAIを覗く#AzureTravelers
hirotomotaguchi
2
510
プロダクトエンジニア 360°フィードバックを実施した話
hacomono
PRO
0
120
抽象化をするということ - 具体と抽象の往復を身につける / Abstraction and concretization
soudai
27
14k
AndroidXR 開発ツールごとの できることできないこと
donabe3
0
130
ソフトウェアエンジニアと仕事するときに知っておいたほうが良いこと / Key points for working with software engineers
pinkumohikan
1
130
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Fireside Chat
paigeccino
34
3.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
350
Building Adaptive Systems
keathley
40
2.4k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Adopting Sorbet at Scale
ufuk
74
9.2k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
Documentation Writing (for coders)
carmenintech
67
4.6k
Transcript
© - BASE, Inc. X \ ⾃作してみよう / xUnitフレームワーク .
. PHP Conference 懇親会LT - @hgsgtk - Let’s make xUnit framework -
© - BASE, Inc. About me BASE BANK, Inc. Dev
Division Tech Lead 『みんなのPHP 現場で役⽴つ最新 ノウハウ!』共著者 (PHPにおけるユニットテスト) https://www.amazon.co.jp/ gp/product/ @hgsgtk Kazuki Higashiguchi
© - BASE, Inc. Do you love PHPUnit?
© - BASE, Inc. I LOVE PHPUnit
© - BASE, Inc. But need more
© - BASE, Inc. If you make xUnit framework
© - BASE, Inc. You will love PHPUnit more!
© - BASE, Inc. Let’s make it!
© - BASE, Inc. By the way, PHPUnit is https://phpunit.de/
© - BASE, Inc. About xUnit Generic name of testing
framework Kent Beck: SUnit (Smalltalk) -> JUnit (Java) Sebastian Bergmann: PHPUnit (PHP) https://en.wikipedia.org/wiki/XUnit
© - BASE, Inc. Main features of xUnit family •
Test Method • Assertion Method • Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』
© - BASE, Inc. Today’s topic • Test Method •
Assertion Method • Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』
© - BASE, Inc. Let’s go
© - BASE, Inc. hgsgtk/mpunit https://github.com/hgsgtk/mpunit
© - BASE, Inc. The Goal is to execute this
test
© - BASE, Inc. • Test Method • Assertion Method
• Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』 Today’s topic
© - BASE, Inc. Make executable command /bin/mpunit
© - BASE, Inc. Find test methods and execute them
.Find test files .Find test classes .Find test methods .Execute test methods
© - BASE, Inc. . Find test files /src/Command.php Collect
files “*Test.php”
© - BASE, Inc. . Find test classes /src/Command.php 定義済みクラスから、ユーザー定義型で
MPUnit\TestCaseを継承して いるを探し出す
© - BASE, Inc. . Find test classes /src/Command.php Get
declared classes
© - BASE, Inc. . Find test classes /src/Command.php Is
user defined?
© - BASE, Inc. . Find test classes /src/Command.php Is
extended MPUnit\TestCase?
© - BASE, Inc. (Tips)PHP feature to collect classes •
get_declared_classes() • 定義済みのクラスの名前を配列として返す • ReflectionClass::isUserDefined() • 内部クラスかどうかを検査 • ReflectionClass::getParentClass() • 親クラスの情報を取得 https://www.php.net/manual/ja/reflectionclass.isuserdefined.php https://www.php.net/manual/ja/function.get-declared-classes.php https://www.php.net/manual/ja/reflectionclass.getparentclass.php
© - BASE, Inc. . Find test methods /src/Command.php テストクラスのPUBLICメソッドから、先頭
が test で始まるメソッドを探す
© - BASE, Inc. . Find test methods /src/Command.php テストクラスのPUBLICメソッドから、先頭
が test で始まるメソッドを探す Find public method which name starts ʻtest’
© - BASE, Inc. (Tips)Gather functions • ReflectionClass::getMethods • クラスのメソッド名を取得
• ReflectionMethod::IS_PUBLIC etc https://www.php.net/manual/ja/reflectionclass.getmethods.php
© - BASE, Inc. . Execute test methods /src/Command.php If
AssertionError => Failed (F) Else => Success (.)
© - BASE, Inc. Understand xUnit • Two strategies to
find test functions • Test Discovery‧Test Enumeration • In Test Discovery, user does not need to register manually • Almost xUnit families’ strategy is Test Discovery
© - BASE, Inc. • Test Method • Assertion Method
• Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』 Today’s topic
© - BASE, Inc. Ways to assert • assert function(PHP)
• (Choice it, because I want to implement with minimum dependencies) • beberlei/assert • webmozart/assert • hamcrest/hamcrest-php etc
© - BASE, Inc. Setting assertion options /bin/mpunit
© - BASE, Inc. (Tips)Setting directive for assertion • zend.assertions
(default: ) • assert()を⽣成するか‧実⾏するか • 1 の場合、コードは⽣成され実⾏される • assert.exception (default: ) • アサーション失敗に指定したオブジェクトをス ロー • 指定なしだとAssertionError https://www.php.net/manual/ja/function.assert.php https://www.php.net/manual/ja/class.assertionerror.php
© - BASE, Inc. (Tips)Options for assertion • 様々なassertフラグを設定できる •
ASSERT_ACTIVE • ASSERT_WARNING • ASSERT_BAIL • ASSERT_QUIET_EVAL • ASSERT_CALLBACK https://www.php.net/manual/ja/function.assert-options.php
© - BASE, Inc. assertion Make assertion method “assertSame”
© - BASE, Inc. • Test Method • Assertion Method
• Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』 Today’s topic
© - BASE, Inc. Run tests, Get report TestCaseを継承したクラスから assertSame
が使えるように Use assertion method in test method
© - BASE, Inc. hgsgtk/mpunit https://github.com/hgsgtk/mpunit Demonstration
© - BASE, Inc. Get Report
© - BASE, Inc. By making xUnit, • PHPUnit has
a lot of features, it’s amazing!! • I also red internal implementations of PHPUnit to make it. I learned a lot.
© - BASE, Inc. LOVE to PHPUnit became STRONGER!! By
making xUnit,
© - BASE, Inc. X Thanks!