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
Specs2入門
Search
Nguyen Hong Phuc
October 21, 2016
Technology
840
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Specs2入門
Nguyen Hong Phuc
October 21, 2016
Other Decks in Technology
See All in Technology
JSAI2026 オーガナイズドセッションOS-27「不動産とAI」趣旨説明 / JSAI2026 Organized Session OS-27 “Real Estate and AI”: Statement of Purpose
ykiyota
0
170
EventBridge Connection
_kensh
5
680
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
130
AIを「創る」と「使う」の循環 — HRテックが実践するリアルなAI組織実装
taketo957
0
1.9k
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
630
チームで実践する AI-DLC 思考の軌跡を残すチェックポイント設計
belongadmin
0
3.2k
脆弱性対応、どこで線を引くか
rymiyamoto
0
340
フロンティアAIのゲート化と地政学リスク
nagatsu
0
110
地球に⽣きるAI —GeoAIと「中間領域」— / AI Living on Earth — GeoAI and the “Intermediate Layer” —
ykiyota
0
200
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development with AI-DLC
yoshidashingo
0
160
失敗を資産に変えるClaude Code
shinyasaita
0
250
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
640
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
330
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
330
KATA
mclloyd
PRO
35
15k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
190
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Making Projects Easy
brettharned
120
6.7k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
4 Signs Your Business is Dying
shpigford
187
22k
Transcript
Specs2テスト入門 Nguyen Hong Phuc (フック)
早速 Specs2でテストを書いてみる
OpenRtb BidRequest Specs Take from https://github.com/openrtb/OpenRTB/blob/master/OpenRTB-API-Specification-Version-2-3-1-FINAL.pdf
BidRequest Class
正確なBidRequestは 1. BidRequest.idが空白文字列ではない 2. BidRequest.impがnon-empty配列 3. BidRequest.imp.idが空白文字列ではない 4. …
Simple BidRequest Test
Simple BidRequest Tests ← CODE IS NOT “DRY” Take from:
http://www.slideshare.net/ardentlearner/the-principles-of-good-programming
Keep our code is DRY with Specs2 style
Specs2のMatcherを使ってみる
Matcherについて データがあれば、それが正しいかどうかを確認したいとき、 最も一般的に利用されるMatcherであります
Matcherについて 赤い下線のところはMatcherです
Matcherの種類 Specs2で色々な Matcherが定義されている - StringMatchers - NumericMatchers - OptionMatchers -
TraversableMatchers - FutureMatchers (scala.concurrent.Future) - FutureZMatchers (scalaz.concurrent.Future向け) - XorMatchers (catsライブラリ向け) - … Reference Card: https://etorreborre.github.io/specs2/guide/SPECS2-3.8.5/org.specs2.guide.matchers.ReferenceCard.html Matcher collection: https://github.com/etorreborre/specs2/tree/master/matcher/src/main/scala/org/specs2/matcher
“beAValidBidRequest” Matcher Create BidRequest Matcher
Before After ➡
テストケースが失敗のとき
実行結果
Expectation Description改善 “aka”を利用する
Expectation Description改善
テストを生成する
テスト生成 Example
実行結果
テストグループに入れてみる
コンパイルできなくなった
def foreach(f: (A) => Unit): Unit
Fragmentsでテストを生成する package org.specs2 package specification package core object Fragments {
… def foreach[T](seq: Seq[T])(f: T => Fragments): Fragments = ... } (c.fhttps://github.com/etorreborre/specs2/blob/master/core/src/main/scala/org/specs2/specification/core/Fragments.s cala#L116-L118)
テストが実行されるようになりました
Fragmentについて “In specs2 a specification can simply be viewed as
a sequence of Fragments.” そしてFragmentは - A Description - An Execution - An Example - ...
FragmentFactory APIでテストを生成する References: https://etorreborre.github.io/specs2/guide/SPECS2-3.8.5/org.specs2.guide.FragmentsApi.html
DataTablesがカッコイイ c.f. https://etorreborre.github.io/specs2/guide/SPECS2-3.8.5/org.specs2.guide.UseDatatables.html
実行結果
Specs2が結構便利なライブラリ ぜひ使ってみてください
Thank you for listening