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
unit tests in ruby
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
SiweiShen
January 03, 2013
Technology
100
1
Share
unit tests in ruby
introduced how to write basic unit tests and how to fasten the execution speed.
SiweiShen
January 03, 2013
More Decks by SiweiShen
See All by SiweiShen
Ruby introduction to QA people
sg552sg552
1
77
ruby introduction ( Chinese)
sg552sg552
1
78
meta programming ruby
sg552sg552
5
240
Other Decks in Technology
See All in Technology
職能の壁を取り払った先で見えた壁 -AI時代のクロスファンクショナル組織-
shimotaroo
1
110
こんなアーキテクチャ図はいやだ / Anti-pattern in AWS Architecture Diagrams
naospon
1
380
明日からドヤれる!超マニアックなAWSセキュリティTips10連発 / 10 Ultra-Niche AWS Security Tips
yuj1osm
0
490
Digitization部 紹介資料
sansan33
PRO
1
7.3k
みんなの「データ活用」を支えるストレージ担当から持ち込むAWS活用/コミュニティー設計TIPS 10選~「作れる」より、「続けられる」設計へ~
yoshiki0705
0
200
ルールルルルル私的函館観光ガイド── 函館の街はイクラでも楽しめる!
nomuson
0
200
新規サービス開発におけるReact Nativeのリアル〜技術選定の裏側と実践的OSS活用〜
grandbig
2
200
LLM とプロンプトエンジニアリング/チューターを定義する / LLMs and Prompt Engineering, and Defining Tutors
ks91
PRO
0
410
AWS認定資格は本当に意味があるのか?
nrinetcom
PRO
1
240
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.1k
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.3k
Featured
See All Featured
It's Worth the Effort
3n
188
29k
30 Presentation Tips
portentint
PRO
1
270
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
97
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
220
Context Engineering - Making Every Token Count
addyosmani
9
820
Typedesign – Prime Four
hannesfritz
42
3k
Un-Boring Meetings
codingconduct
0
260
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Speed Design
sergeychernyshev
33
1.6k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
490
Transcript
Mocks in unit test of Ruby 申思维 Siwei
什 要用 元 ? 为 么 单 测试 Why UT?
➲ 1. 把 手 操作 下来, 成自 。 动 记录 变 动 Manual Operations => Automatic ➲ 2. 可以多次运行,是持 集成 的基 。 续 测试 础 The Basic of Continous Integration ➲ 3. 运行方便,极大减 程序 担。 轻 员负 Save developer's life.
比 对 IRB: > a = 1 > b =
2 > puts a + b > 3 Unit test: def test_should_show_1_add_2 a = 1; b = 2; assert a+b == 3 end
中的 现实 问题 Problems we met 某个 目, 始了一年, 运行需要与
项 开 3 个外部系 配合: 统 An existing app interacting with 3 external systems: ➲ 1. web service system ➲ 2. authentication system ➲ 3. authorization system
中的 现实 问题 The situation of test cases. 元 的情况:
单 测试 ➲ 1. 400 test cases. 2. too slow. 20+ minutes. 3. not stable , 5% 的 WEB SERVICE test cases will fail.
后果 Results ➲ 人 越来越不想运行 元 。 开发 员 单
测试 Developers don't want to use Unit tests. ➲ 程中,容易走神。( 开发过 20 分 的 ) 钟 时间 Developers often lost their focus during the coding. ➲ 出 率太高。 错 Not stable 直接 致了,系 以 ,想想就 大。 导 统难 维护 头 用 成 人 ,体 十分不好。 户 为测试 员 验
解决方案 Solutions 目 : 短 元 运行的 。 标 缩
单 测试 时间 Target :shorten the running time. 手段: 使用 模 象 和方法。 拟对 ➲ 原来: 用一次,需要 调 15 秒。 Before : 15 s ➲ 模 象: 拟对 0.00xx 秒。 Now: 0.000x s 1. Mock : for objects. 2. Stub : for methods.
Mock Object Real object: ( cost 15 seconds) class DeviceResource
def query(parameters) return json.decode(service(parameters)) end end Mock object: ( 0.000x seconds) class DeviceResource def query(parameters) return “{ status: success, id: 3 }” end end
Stub a method def get_name return “Jim” end get_name #
=> “Jim” require 'rspec-mock' stub(:get_name).and_return (“Kate”) get_name # => “Kate”
Two Mode for Running the Test ➲ 1. the mock
mode: $ rpsec spec ➲ 2. also supports the real mode: $ rspec spec with_real_webservice=true
The result ➲ 目更好了 项 Project becomes better: 1. 代
量更高 码质 .higher code quality. 2. 速度更快 开发 faster development & delivery. 3. 更少。用 更 意 错误 户 满 . less bugs.
结论 Conclusion ➲ 是使用 元 。 总 单 测试 Always
use unit tests. ➲ 元 :可重 ,速度快, 定。( 让单 测试 复 稳 make unit tests faster, stable and reusable )
Thank you ! 谢谢 申思 维 Siwei Shen
[email protected]
http://shensiwei.com