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
130
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Test with :)
The slides for Rubyconf China 2013 with animation off
aquajach
October 26, 2013
More Decks by aquajach
See All by aquajach
Separate the data logic from your application
aquajach
0
84
Grow from Small Simple Steps
aquajach
0
490
Other Decks in Technology
See All in Technology
2026TECHFRESH畢業分享會 - Lightning Talk - E起 See See : 電商推薦讀心術? 數據說了算
line_developers_tw
PRO
0
730
200個のGitHubリポジトリを横断調査したかった
icck
0
100
【Cyber-sec+】経営層を"動かす"ための考え方
hssh2_bin
0
120
Building applications in the Gemini API family.
line_developers_tw
PRO
0
2.9k
LLMにもCAP定理があるという話
harukasakihara
0
280
JSAI2026 オーガナイズドセッションOS-27「不動産とAI」趣旨説明 / JSAI2026 Organized Session OS-27 “Real Estate and AI”: Statement of Purpose
ykiyota
0
220
チームで進めるAI駆動アジャイル×ウォーターフォール
kumaiu
0
150
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
1k
あなたの AI ワークスペースに、 専門コーダーを連れてくる - Amazon Quick Desktop 最新情報
kawaji_scratch
1
130
protovalidate-es を導入してみた
bengo4com
0
170
AI Engineering Summit Tokyo 2026 AIの前に、やることがある 〜医療データ企業の4フェーズ〜
dtaniwaki
0
2.5k
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
30
24k
Featured
See All Featured
A designer walks into a library…
pauljervisheath
211
24k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
380
The Curious Case for Waylosing
cassininazir
1
380
Become a Pro
speakerdeck
PRO
31
6k
Test your architecture with Archunit
thirion
1
2.3k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
850
RailsConf 2023
tenderlove
30
1.5k
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