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
Test with :)
Search
aquajach
October 26, 2013
Technology
3
120
Test with :)
The slides for Rubyconf China 2013 with animation off
aquajach
October 26, 2013
Tweet
Share
More Decks by aquajach
See All by aquajach
Separate the data logic from your application
aquajach
0
78
Grow from Small Simple Steps
aquajach
0
420
Other Decks in Technology
See All in Technology
Google Cloud で学ぶデータエンジニアリング入門 2025年版 #GoogleCloudNext / 20250805
kazaneya
PRO
20
4.7k
Kiroでインフラ要件定義~テスト を実施してみた
nagisa53
3
340
LLMで構造化出力の成功率をグンと上げる方法
keisuketakiguchi
0
730
Intro to Software Startups: Spring 2025
arnabdotorg
0
240
S3 Glacier のデータを Athena からクエリしようとしたらどうなるのか/try-to-query-s3-glacier-from-athena
emiki
0
210
僕たちが「開発しやすさ」を求め 模索し続けたアーキテクチャ #アーキテクチャ勉強会_findy
bengo4com
0
2.3k
VLMサービスを用いた請求書データ化検証 / SaaSxML_Session_1
sansan_randd
0
240
九州の人に知ってもらいたいGISスポット / gis spot in kyushu 2025
sakaik
0
130
反脆弱性(アンチフラジャイル)とデータ基盤構築
cuebic9bic
3
170
20250807_Kiroと私の反省会
riz3f7
0
200
Tableau API連携の罠!?脱スプシを夢見たはずが、逆に依存を深めた話
cuebic9bic
3
220
LLMでAI-OCR、実際どうなの? / llm_ai_ocr_layerx_bet_ai_day_lt
sbrf248
0
450
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
1k
Measuring & Analyzing Core Web Vitals
bluesmoon
8
550
For a Future-Friendly Web
brad_frost
179
9.9k
Making the Leap to Tech Lead
cromwellryan
134
9.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Become a Pro
speakerdeck
PRO
29
5.5k
A Modern Web Designer's Workflow
chriscoyier
695
190k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Optimizing for Happiness
mojombo
379
70k
BBQ
matthewcrist
89
9.8k
Done Done
chrislema
185
16k
Transcript
test with :) chen songyong
about me
about me • Remote worker! • Worked in start-ups, web
consultancies , banks and digital agencies! • @aquajach in Twitter & Github
test in old days
do you ❤️ write test? do you write test?
Q & A
why you test • Forget to go for test first
technical debt "we have not found anything to ease the
transition from 'hairball of code with no unit tests' to 'unit-testable code'."
trust your mind code
my practice integration test controller test model / lib test
my practice Test Implementation “Pay” button works controller deals with
pay request model/lib makes the transaction views controller model/lib pass pass pass
why you test • Forget to write test first! •
Too much extra work
is it true? Writing test adds 15-35% development time in
return for a 40-90% reduction in defect density on otherwise like-for-like projects. - A paper in ESE •YES
is it true? •No! v.s. test in rails console
why you test • Forget to write test first! •
Extra work! • Maintenance is painful
it 'Sign Up should have title' do! visit '/tc/'! page.find('div#sign-up-modal').should
have_css(‘#modalHeader.h5-sign-up-header’, :text => “Apple Now”) ! end
why you test • Forget to write test first! •
Extra work! • Maintenance is painful! • Running test takes longer and longer
easiest way to go • CPU! ! • Data storage!
! • Memory
test suite example • ruby 2.0.0 / rails 3.2.13 /
rspec-rails ~>2.0 / PostgreSQL /Factory Girl / Database cleaner! • 370+ mixed with unit test, integration test (w/ capybara inc. JavaScript)! • No remote request (w/ VCR)
Tool / Framework • spork! • zeus! • spring! •
Parallel test! • Guard! • … … Ryan Bates’ Railscasts SKIP
rspec v.s. rake spec Update: run via bin/rspec
database clean strategy • :transaction! • simply rollback - fastest!
• Failed at:! • multiple connections! • integration test
database clean strategy • :truncation! • TRUNCATE table! • remove
all records! • VACUUM table! • index! • Failed at:! • concurrent access to a table
database clean strategy • :deletion! • DELETE from table! •
scan the table! • less predictable! • Bad at:! • Large tables
Deletion Truncation
database Clean strategy
refactor gemfile • stop loading gems not used in the
code! • e.g. gem ‘unicorn’, require: false! • specify dependencies for test environment! • ‘jquery-rails’, ‘will_paginate’, ‘exception_notification’
defer garbage collection
Original + rspec command + DB clean strategy + refactor
Gemfile + delay garbage collection 0 65 130 195 260
factory v.s. fixture • Flexibility! ! • Callbacks & validations!
! • Speed
! best practice • create(:user) v.s. build(:user) v.s. build_stubbed(:user)! •
require ‘spec_helper’ v.s. require ‘lib_class.rb’! • mock/stub or not to mock/stub! • let v.s. let! v.s. before block
not about speed but... • Selective testing! • slow! •
focus! • Fail immediately --fail-fast! • Display message immediately! -- format Fuubar! • rspec -p spec
(real) Q & A