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
410
Other Decks in Technology
See All in Technology
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.2k
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
2.7k
スプリントゴール未達症候群に送る処方箋
kakehashi
PRO
1
170
ソフトウェアQAがハードウェアの人になったの
mineo_matsuya
3
250
複数のGemini CLIが同時開発する狂気 - Jujutsuが実現するAIエージェント協調の新世界
gunta
7
1.9k
Shadow DOM & Security - Exploring the boundary between light and shadow
masatokinugawa
0
630
エンジニアリングマネージャー“お悩み相談”パネルセッション
ar_tama
1
520
Frontier Airlines Customer®️ USA Contact Numbers: Complete 2025 Support Guide
frontierairlineswithflyagent
0
100
claude codeでPrompt Engineering
iori0311
0
260
AI Ready API ─ AI時代に求められるAPI設計とは?/ AI-Ready API - Designing MCP and APIs in the AI Era
yokawasa
20
5.4k
データ戦略部門 紹介資料
sansan33
PRO
1
3.3k
Microsoft Fabric ガバナンス設計の一歩目を考える
ryomaru0825
1
170
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1031
460k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
The Invisible Side of Design
smashingmag
301
51k
Faster Mobile Websites
deanohume
308
31k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Raft: Consensus for Rubyists
vanstee
140
7k
Facilitating Awesome Meetings
lara
54
6.5k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
710
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
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