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
850
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
LangfuseによるLLMOps基盤の構築と活用事例
zozotech
PRO
0
150
テックカンファレンス三大ステークホルダーの文化人類学 ─ 違いを認め合う関係性作り
bash0c7
4
1k
Claude Mythos、Fable...フロンティアAIの最新動向と企業のセキュリティ対策
flatt_security
0
170
最新IoT事例11選に学ぶ!現場の成功パターンと実践のコツ【SORACOM Discovery 2026】
soracom
PRO
0
120
NetBoxを利用した作業効率化の試み_NetDevNight4
tnoha
0
300
WEBフロントエンド研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
720
システム監視入門
grimoh
5
740
どこまでAIに任せるか 〜確率論と決定論の境界決定〜
shukob
0
560
検索技術知識0のエンジニアが広告検索システムを内製化して運用するまで
lycorptech_jp
PRO
0
150
Power Automateアップデート情報
miyakemito
0
280
現場で使える AWS DevOps Agent 活用ノウハウ - Release Management 機能の検証結果を添えて / AWS DevOps Agent Release Management and Know-How
kinunori
4
750
オートマトンと字句解析でRoslynを読む
tomokusaba
0
120
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Scaling GitHub
holman
464
140k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
330
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
230
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
760
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
430
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
370
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