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
860
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
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
17
7.6k
What's new in Go 1.27?
ciarana
0
260
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
130
QAエンジニア起点で進める、SmartHRにおける信頼性向上について
kaomi_wombat
1
150
Adding Right-to-Left support to your web application with CSS logical properties — Lessons from Redmine
vividtone
0
130
まちスペース®とデジタルツインと「まちづくり」
hiro_ogi
0
130
エンドユーザー視点で見る SansanのMeraki活用と内製自動化
sansantech
PRO
0
120
コネクションをピン留めさせずに SELECTクエリのタイムアウトを設定した話
codmoninc
0
140
AIのためのEthernet技術動向 (SerDes)
markunet
1
220
Bits AI を制するものは Datadog を制す / The player that controls Bits AI, controls Datadog
kaminashi
0
130
小粒でもパワフルなJS Runtime Antjsについて
comamoca
0
100
FPGAが実現する遠方宇宙の高空間分解能天体撮影 -大型地上望遠鏡の視力を補正する「補償光学」とは?-
komei_mt
0
500
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
480
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
390
The Mindset for Success: Future Career Progression
greggifford
PRO
0
450
The Language of Interfaces
destraynor
162
27k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
210
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
370
エンジニアに許された特別な時間の終わり
watany
108
250k
KATA
mclloyd
PRO
35
15k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
470
WCS-LA-2024
lcolladotor
0
800
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
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