Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
unit tests in ruby
Search
SiweiShen
January 03, 2013
Technology
120
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
unit tests in ruby
introduced how to write basic unit tests and how to fasten the execution speed.
SiweiShen
January 03, 2013
Transcript
13 slides
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
More Decks by SiweiShen
See All by SiweiShen
Ruby introduction to QA people
sg552sg552
1
88
ruby introduction ( Chinese)
sg552sg552
1
110
meta programming ruby
sg552sg552
5
280
Other Decks in Technology
See All in Technology
Web Performance Is a Journey [PerfNow 2026]
tammyeverts
3
170
IVRy における AI 時代のデータプロダクトと事業開発
ivry_presentationmaterials
0
120
New Relicのアラート対応をClaude Codeで自動修正するワークフローを作った話
manabuseki
3
700
認知負荷の減らし方 ~開発にも日常業務にも活かせるノウハウ~
minorun365
PRO
18
16k
競馬予想をAIでやってみた話
yoshimura_datam
0
130
Claude Certified Developer – Professional 試験対策
shinoisa
0
210
NutanixへのSSHアクセスの今後について
shadowhat
0
180
その修正で本当に速くなったのか? k6とOpenTelemetryで確かめる性能改善 / Performance review with k6 and OpenTelemetry
ymotongpoo
3
460
さようならSSH鍵、こんにちはゼロトラスト ― AIフレンドリーで快適な自宅鯖SSH
atalie2m
14
7.6k
サーバーラックは作る時代! 3Dプリンターで作る10インチラックのススメ
jacopen
2
520
Platform Engineering をベースとした Agentic Software Factory の実践
110y
3
1k
エンタープライズIAMについて - ID・権限をどう統制するか
oidfj
1
350
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
610
How Software Deployment tools have changed in the past 20 years
geshan
3
35k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
61k
Well, that’s weird…
csswizardry
3
240
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
570
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
69k
Become a Pro
speakerdeck
PRO
31
6.4k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
4 Signs Your Business is Dying
shpigford
187
23k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
630