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
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
250
RAGの精度向上とエージェント活用
kintotechdev
2
120
はてなのサービス基盤を支える Kubernetes《足腰》
masayoshimaezawa
0
430
次世代ランサムウェア対策の考察 / 20260704 Mitsutoshi Matsuo
shift_evolve
PRO
5
1.7k
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
350
組織における AI-DLC 実践
askul
0
300
AI時代のエンジニアキャリアについて今一度考える
sakamoto_582
1
930
感情と身体を置き去りにしない、エンジニアの生きのこり方 ──いまから、ここから「自分の状態」を扱うという選択
saorimurooka
1
470
初めてのDatabricks勉強会
taka_aki
2
230
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
150
AIDLC_ヤフーショッピングの取り組み
lycorptech_jp
PRO
0
510
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
230
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Design in an AI World
tapps
1
260
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Designing for Performance
lara
611
70k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
630
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Building Adaptive Systems
keathley
44
3.1k
Navigating Weather and Climate Data
rabernat
0
270
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.7k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
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