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.4k
自作してみよう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
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.3k
HTTP Tunneling in Go
hgsgtk
0
1.3k
ブラウザ自動操作技術の深層へ、直接触れて学ぶ WebDriver と Chrome DevTools Protocol
hgsgtk
3
6.4k
HTTP Server on random available port in Go
hgsgtk
0
920
Agile Testingを夢見たテスト自動化 〜ATDDへの挑戦から始まる 1年間の試行錯誤〜 / dreaming agile testing at basebank
hgsgtk
14
7.6k
Create Go WebDriver client from scratch
hgsgtk
1
2.1k
PHPでWeb Driver Clientを自作する〜己の手でブラウザ操作自動化を完全理解する方法〜 / phpcon2021
hgsgtk
2
2.4k
振り返りを積み上げて自分たちのプラクティスとして昇華•体得していくための仕組みと考え方 / ScrumFestMikawa2021
hgsgtk
3
2.4k
Other Decks in Technology
See All in Technology
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Terraform Stacks入門 #HashiTalks
msato
0
350
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
Taming you application's environments
salaboy
0
180
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
210
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Visualization
eitanlees
145
15k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Ruby is Unlike a Banana
tanoku
97
11k
Agile that works and the tools we love
rasmusluckow
327
21k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Side Projects
sachag
452
42k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Scaling GitHub
holman
458
140k
Docker and Python
trallard
40
3.1k
Producing Creativity
orderedlist
PRO
341
39k
Practical Orchestrator
shlominoach
186
10k
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!