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
5k
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
Raycast AI APIを使ってちょっと便利な拡張機能を作ってみた / created-a-handy-extension-using-the-raycast-ai-api
kawamataryo
0
190
抽象化をするということ - 具体と抽象の往復を身につける / Abstraction and concretization
soudai
27
15k
NFV基盤のOpenStack更新 ~9世代バージョンアップへの挑戦~
vtj
0
330
ソフトウェアエンジニアと仕事するときに知っておいたほうが良いこと / Key points for working with software engineers
pinkumohikan
1
140
生成 AI プロダクトを育てる技術 〜データ品質向上による継続的な価値創出の実践〜
icoxfog417
PRO
5
1.9k
EDRの検知の仕組みと検知回避について
chayakonanaika
11
4.3k
脳波を用いた嗜好マッチングシステム
hokkey621
0
280
実は強い 非ViTな画像認識モデル
tattaka
1
1.1k
偏光画像処理ライブラリを作った話
elerac
1
160
Reading Code Is Harder Than Writing It
trishagee
2
120
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
17
45k
AWSではじめる Web APIテスト実践ガイド / A practical guide to testing Web APIs on AWS
yokawasa
5
220
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
Facilitating Awesome Meetings
lara
52
6.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Bash Introduction
62gerente
611
210k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
52k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
The Invisible Side of Design
smashingmag
299
50k
Code Reviewing Like a Champion
maltzj
521
39k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
The Pragmatic Product Professional
lauravandoore
32
6.4k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
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!